Location: PHPKode > projects > PhpScribe Documentation Generator > examples.php
<?php
require_once("config/scribe.inc");
require_once(PHPSCRIBE_CLASS_HTML);
require_once(PHPSCRIBE_CLASS_FORMTEMPLATE);
require_once(PHPSCRIBE_CLASS_REPORT);

$HTML = new Html();
$HTML->addStyle("phpscribe.css");
$HTML->addBodyCfg("bgColor='#d6d6d6'");
$HTML->makePage();
$HTML->header->setAndPrepare("header.tpl");
$HTML->header->replace(array("imagePath"=>PHPSCRIBE_IMAGE_PATH,
                             "localPath"=>PHPSCRIBE_ABSOLUTE_PATH,
                             "pageTitle"=>"Examples and Use Cases"));
$HTML->footer->setAndPrepare("footer.tpl");
$HTML->footer->replace(array("imagePath"=>PHPSCRIBE_IMAGE_PATH,
                             "localPath"=>PHPSCRIBE_ABSOLUTE_PATH));
$HTML->printPage();

function Main() {
     if (!empty($_POST)) {
          SaveData($_POST,$GLOBALS['message']);
     } elseif (isset($_GET['delete'])) {
          DeleteData($_GET['delete'],$GLOBALS['message']);
     }
     $MAIN_TPL = new Template(PHPSCRIBE_TEMPLATE_PATH."main.tpl");
     $MAIN_TPL->prepare();
     $MAIN_TPL->assign("mainContent",GetActContent());
     $MAIN_TPL->assign("imagePath",PHPSCRIBE_IMAGE_PATH);
     $MAIN_TPL->printToScreen();
     if ((isset($_GET['codProject'])) && ($_GET['pageAction'] == "form")) {
          focus("example","cod_function");
     }
     if ($GLOBALS['message'] != "") alert($GLOBALS['message']);
}

function GetActContent() {
     $DB = new Db();
     if ((isset($_GET['codProject'])) && (isset($_GET['pageAction']) && ($_GET['pageAction'] == "form"))) {
          $RS = $DB->Query("SELECT * FROM project WHERE cod_project = ".$_GET['codProject']);
          if ($DB->affectedRows() > 0) {
               if (isset($_GET['edit'])) {
                    $DB = new Db();
                    $DB->toGlobals("SELECT * FROM example WHERE cod_example = ".$_GET['edit']);
               }
               $FORM = new formTemplate(PHPSCRIBE_XML_PATH."example.xml",PHPSCRIBE_TEMPLATE_PATH."example.tpl","example",$_SERVER['REQUEST_URI'],"POST");
               $FORM->Document = &$GLOBALS['HTML'];
               $FORM->inputStyle = "normal";
               $FORM->labelStyle = "subnav";
               $FORM->buttonStyle = "button";
               $FORM->jsPath = PHPSCRIBE_JAVASCRIPT_PATH;
               $FORM->processXML();
               return $FORM->getContents();
          } else {
               return "<BR><CENTER><SPAN CLASS='subnav'>Invalid Project</SPAN><BR><BR><A HREF='javascript:history.go(-1);' ".mouseOver("Back")." CLASS='normalblue'>« Back</A></CENTER>";
          }
     } else {
          $FORM = new formTemplate(PHPSCRIBE_XML_PATH."choose_project.xml",PHPSCRIBE_TEMPLATE_PATH."choose_project.tpl","choose_project",$_SERVER['PHP_SELF'],"GET");
          $FORM->Document = &$GLOBALS['HTML'];
          $FORM->inputStyle = "normal";
          $FORM->labelStyle = "subnav";
          $FORM->buttonStyle = "button";
          $FORM->jsPath = PHPSCRIBE_JAVASCRIPT_PATH;
          $FORM->processXML();

          if (isset($_GET['codProject'])) {
               $RS = $DB->Query("SELECT * FROM project WHERE cod_project = ".$_GET['codProject']);
               if ($RS && $RS->RecordCount() > 0) {
                    $RS = $DB->Query("SELECT cod_revision FROM revision WHERE cod_project = ".$_GET['codProject']);
                    if ($DB->affectedRows() > 0) {
                         $FORM->assignValue("addLink","<A HREF='examples.php?codProject=".$_GET['codProject']."&pageAction=form' CLASS='normalblue' ".mouseOver("add an example").">Add an Example</A>");
                         $return = $FORM->getContents();
                         $REPORT = new Report("report2.tpl",TRUE);
                         $REPORT->fields = "IF(c.cod_class IS NOT NULL,CONCAT(c.name,'::',f.name),f.name) AS 'Function',
                                            CONCAT('<I>',LEFT(e.description,60),'...</I>') AS 'Example',
                                            CONCAT('<A CLASS=normalblue HREF=\"examples.php?codProject=".$_GET['codProject']."&pageAction=form&edit=',e.cod_example,'\">Edit</A>') AS ' ',
                                            CONCAT('<A CLASS=normalblue HREF=\"examples.php?codProject=".$_GET['codProject']."&pageAction=list&delete=',e.cod_example,'\">Remove</A>') AS ' '";
                         $REPORT->tables = "function f
                                            LEFT JOIN class c ON(f.cod_class=c.cod_class)
                                            INNER JOIN example e ON(f.cod_function=e.cod_function)
                                            INNER JOIN revision r ON(f.revision=r.cod_revision)";
                         $REPORT->where = "r.cod_project = ".$_GET['codProject'];
                         $REPORT->orderby = "f.name";
                         $REPORT->jsPath = PHPSCRIBE_JAVASCRIPT_PATH;
                         $REPORT->noRegTpl = "noexample.tpl";
                         $REPORT->setColumnSizes(array(22,61,6,11));
                         $REPORT->setMaxRows(10);
                         $REPORT->setLinkCss("subnav");
                         $REPORT->appendExtraVars("&codProject=".$_GET['codProject']."&pageAction=list");
                         $REPORT->buildPage();
                         $return .= $REPORT->getContents();
                    } else {
                         $FORM->assignValue("addLink","");
                         $return = $FORM->getContents();
                         $NOREV = new Template(PHPSCRIBE_TEMPLATE_PATH."norevision.tpl");
                         $NOREV->prepare();
                         $return .= $NOREV->getOutputContent();
                    }
               } else {
                    $FORM->assignValue("addLink","");
                    $return = $FORM->getContents()."<BR><CENTER><SPAN CLASS='subnav'>Invalid Project</SPAN><BR></CENTER>";;
               }
          } else {
               $FORM->assignValue("addLink","");
               $return = $FORM->getContents();
          }
          return $return;
     }
}

function SaveData(&$postData,&$message)
{
     $DB = new Db();
     if ((!isset($postData['cod_example'])) || ($postData['cod_example'] == "")) {
          $postData['description'] = str_replace("\\'","'",$postData['description']);
          $postData['description'] = str_replace("\\\"","\"",$postData['description']);
          $GLOBALS['description'] = $postData['description'];
          $DB->Insert("example",$postData);
          if ($DB->AffectedRows() > 0) {
               $message = "Example created successfully!";
               $_GET['pageAction'] = "list"; // switch to project list
               return TRUE;
          } else {
               $message = "Example couldn't be created!";
               return FALSE;
          }
     } else {
          $postData['description'] = str_replace("\\'","'",$postData['description']);
          $postData['description'] = str_replace("\\\"","\"",$postData['description']);
          $GLOBALS['description'] = $postData['description'];
          $DB->Update("example",$postData,"cod_example = ".$postData['cod_example']);
          $message = "Example updated successfully!";
          $_GET['pageAction'] = "list"; // switch to project list
          return TRUE;
     }
}

function DeleteData($data,&$message) {
     $DB = new Db();
     $RS = $DB->Query("SELECT cod_example FROM example WHERE cod_example = ".$data);
     if ($RS && $RS->REcordCount() > 0) {
          $DB->Delete("example","cod_example=".$data);
          $message = "Example deleted successfully";
          return TRUE;
     } else {
          $message = "This example is invalid or has already been deleted!";
          return FALSE;
     }
}
?>
Return current item: PhpScribe Documentation Generator