PHP Classes

File: sample_gui.php

Recommend this page to a friend!
  Classes of Tomasz Malewski   adv_wdt   sample_gui.php   Download  
File: sample_gui.php
Role: Example script
Content type: text/plain
Description: Example of GUI
Class: adv_wdt
Track changes of pages in a MySQL database
Author: By
Last change: Accessible for everbody
Date: 13 years ago
Size: 3,158 bytes
 

Contents

Class file image Download
<?php

// Sample GUI for adv_wdt php class for tracking webpage update changes.

$sqlhost='localhost';
$sqluser='username';
$sqlpass='password';
$sqldb='dbname';
$sqltable='adv_wdt';
include
'adv_wdt.php';

// POST section
if ($_POST[action]=='sql_addURL') {
   
$wdt = new adv_wdt;
   
$wdt->sql_connect ($sqlhost,$sqluser,$sqlpass,$sqldb,$sqltable); // connect to temporary SQL table, need create first one
   
$wdt->sql_addURL($_POST[url]); // Only testing, never ever use in production SQL direct $_POST variable :D
   
echo "<li> Added new URL ".$_POST[url]."<br>";
    }
// addURL

if ($_POST[action]=='CHECK') {
   
$wdt = new adv_wdt;
   
$wdt->sql_connect ($sqlhost,$sqluser,$sqlpass,$sqldb,$sqltable); // connect to temporary SQL table, need create first one
   
$wdt->sql_diffURL($_POST[url]); // Only testing, never ever use in production SQL direct $_POST variable :D
   
echo "<li> Checked URL for a changes ".$_POST[url]."<br>";
    }
// check

if ($_POST[action]=='UPDATE') {
   
$con = mysql_connect($sqlhost.':'.$sqlport, $sqluser, $sqlpass);
   
mysql_select_db($sqldb,$con);
   
mysql_query("update ".$sqltable." set changed='".$_POST[changed]."',active='".$_POST[active]."',margin='".$_POST[margin]."' where `URL`='".$_POST[url]."' limit 1") or die(mysql_error()); // last step update record
   
echo "<li> Manual update for ".$_POST[url]."<br>";
    }
// update

// POST section end


$con = mysql_connect($sqlhost.':'.$sqlport, $sqluser, $sqlpass);
mysql_select_db($sqldb,$con);
echo
"Current records in table:<br><table border=1><tr>
    <TH>URL</TH>
    <TH>Created</TH>
    <TH>Active</TH>
    <TH>Changed</TH>
    <TH>Length</TH>
    <TH>Margin</TH>
    <TH>checksum</TH>
    <TH>updated</TH>
    </tr>"
;
   
$sqlq1="select * from ".$sqltable." order by active desc,changed desc, URL asc limit 100";
       
$sqlq1b=mysql_query($sqlq1) or die(mysql_error());
        while(
$sqlq1c = mysql_fetch_assoc($sqlq1b)) {
// print_r ($sqlq1c);
           
echo "<TR bgcolor='";
            if (
$sqlq1c[active]==1 && $sqlq1c[changed]==1) {echo 'pink';}
            if (
$sqlq1c[active]==1 && $sqlq1c[changed]==0) {echo 'lightgreen';}
            if (
$sqlq1c[active]==0 ) {echo 'lightgrey';}
            if (
strlen($sqlq1c[URL])>40) { $URL_short = substr($sqlq1c[URL],0,15).'...'.substr($sqlq1c[URL],-20);}
                else {
$URL_short = $sqlq1c[URL];}
            echo
"'><FORM METHOD=POST>
                <TD NOWRAP><a href='"
.$sqlq1c[URL]."'>".$URL_short."</a><INPUT TYPE=HIDDEN name=url value='$sqlq1c[URL]'></TD>
                <TD>
$sqlq1c[create_DT]</TD>
                <TD><input type=text name=active value='
$sqlq1c[active]' size=1></TD>
                <TD><input type=text name=changed value='
$sqlq1c[changed]' size=1></TD>
                <TD>
$sqlq1c[length]</TD>
                <TD><input type=text name=margin value='
$sqlq1c[margin]' size=2></TD>
                <TD>
$sqlq1c[checksum]</TD>
                <TD>
$sqlq1c[update_DT]</TD>
                <TD NOWRAP><INPUT TYPE=SUBMIT NAME=action VALUE=UPDATE> | <INPUT TYPE=SUBMIT NAME=action VALUE=CHECK></TD>
                </FORM></TR>
            "
;
    }
// sqlq1c
echo "<TR><TD>_</TD></TR><TR><FORM method=POST>
    <TD >ADD:<input type=text name=url></TD>
    <TD><input type=submit name=action value=sql_addURL></TD>
    </FORM></TR></table>"
;

exit;
?>