Advertisement
Guest User

Robert

a guest
Apr 8th, 2010
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.59 KB | None | 0 0
  1. When the object is created in index.php, the method HTMLEditorHandler() is called
  2.  
  3. <?php
  4.  
  5. class HTMLEditor{
  6.    
  7.     var $isNew;
  8.    
  9.     function SaveChanges($author, $company, $title, $content, $new){
  10.         // Get AuthorID
  11.         // Search database for ID
  12.         $sql="SELECT ID";
  13.         $sql.=" FROM authors";
  14.         $sql.=" WHERE Name = '$author'";
  15.         $author_id=$this->db->getOne($sql);
  16.         // If author not found, add to database
  17.         if(!$author_id){
  18.             $sql="INSERT INTO authors(Name)";
  19.             $sql.="VALUES ('{$author}')";
  20.             $this->db->query($sql);
  21.             $author_id=mysql_insert_id();
  22.         }
  23.         print "isNew: ".$this->isNew;
  24.         /*if($this->isNew==1){
  25.             $sql="INSERT INTO pages(CompanyID, AuthorID, Title, Content, DateCreated, DateUpdated)";
  26.             $sql.=" VALUES ('{$company}', '{$author_id}', '{$title}', '{$content}', NOW(), NOW())";
  27.             $this->db->query($sql);
  28.         } else if($this->isNew==0){
  29.             print "Not new";
  30.         }*/
  31.     }
  32.    
  33.     function EditForm($isNew){
  34.         if(isset($_POST['pageID'])){
  35.             $sql="SELECT Name, Title, Content, CompanyID";
  36.             $sql.=" FROM pages, authors\n";
  37.             $sql.=" WHERE pages.AuthorID = authors.ID";
  38.             $sql.=" AND pages.ID = '".$_POST['pageID']."'";
  39.                            
  40.             $result=$this->db->query($sql);
  41.             $row=$result->fetchRow();
  42.             $company=$row['CompanyID'];
  43.         }
  44.         print "<form action=\"{$_SERVER['PHP_SELF']}\" method=\"post\">\n";
  45.             print "<table width=\"100%\"summary=\"New Page\"\n>";
  46.                 print "<tr>\n";
  47.                     print "<th>Author: </th>\n";
  48.                     print "<td><input type=\"text\" name=\"author\"";
  49.                         if(isset($row['Name'])){
  50.                             print "value=\"".$row['Name']."\"";
  51.                         }
  52.                     print "/></td>\n";
  53.                 print "</tr>\n";
  54.                 print "<tr>\n";
  55.                     print "<th>Company: </th>\n";
  56.                     print "<td>\n";
  57.                         $this->ShowCompanies($company);
  58.                     print "</td>\n";
  59.                 print "</tr>\n";
  60.                 print "<tr>\n";
  61.                     print "<th>Title: </th>\n";
  62.                     print "<td><input type=\"text\" name=\"title\"";
  63.                         if(isset($row['Title'])){
  64.                             print "value=\"".$row['Title']."\"";
  65.                         }
  66.                     print "/></td>\n";
  67.                 print "</tr>\n";
  68.                 print "<tr>\n";
  69.                     print "<th>Content: </th>\n";
  70.                     print "<td>\n";
  71.                         print $this->myToolBar->EditableArea("content", htmlspecialchars($row['Content']), "100%", 400, "NoSave");
  72.                     print "</td>\n";
  73.                 print "</tr>\n";
  74.             print "</table>\n";
  75.             print "<input type=\"submit\" name=\"save\" value=\"Save\"/>\n";
  76.             print "<input type=\"submit\" name=\"\" value=\"Cancel\"/>\n";
  77.         print "</form>\n";
  78.     }
  79.    
  80.     function DefaultForm(){
  81.         print "<form action=\"{$_SERVER['PHP_SELF']}\" method=\"post\">\n";
  82.             print "<input type=\"submit\" name=\"new_page\" value=\"Create a new page\"/>";
  83.             print "<h2>Edit an existing page</h2>\n";
  84.             print "<table summary=\"Edit Page\">\n";
  85.                 print "<tr><th>Year</th><td>";
  86.                     print "<select name=\"year\" onchange=\"showPages()\" id=\"year_select\">\n";
  87.                     for ($year=date('Y'), $max_year=date('Y')-10; $year > $max_year; $year--) {
  88.                             print "<option value=\"".$year."\">".$year."</option>\n";
  89.                         }
  90.                     print "</select>\n";
  91.                 print "</td></tr>";
  92.                 print "<tr><th>Company: </th><td>";
  93.                     $sql="SELECT organisations.OrgID, companynames.CompanyName";
  94.                     $sql.=" FROM qsvision.organisations";
  95.                     $sql.=" LEFT JOIN qsvision.companynames";
  96.                     $sql.=" ON qsvision.organisations.CompanyID=qsvision.companynames.CompanyID";
  97.                     $sql.=" WHERE CompanyName!=''";
  98.                     $sql.=" GROUP BY companynames.CompanyID";
  99.                     $sql.=" ORDER BY companynames.CompanyName ASC";
  100.                     $organisations=$this->db->getAll($sql);
  101.                    
  102.                     print "<select name=\"org_id\" onchange=\"showPages()\" id=\"org_id\">\n";
  103.                         print "<option value=\"\">[Select...]</option>\n";
  104.                         for($i=0, $max_i=count($organisations); $i<$max_i; $i++){
  105.                             print "<option value=\"{$organisations[$i]['OrgID']}\"";
  106.                             if($site['OrgID']==$organisations[$i]['OrgID']){
  107.                                 print " selected=\"selected\"";
  108.                             }
  109.                             print ">".htmlspecialchars($organisations[$i]['CompanyName'])."</option>\n";
  110.                         }
  111.                     print "</select>\n";
  112.                 print "</td></tr>\n";
  113.                 print "</table>";
  114.                 print "<div id=\"results_table\"></div>";
  115.         print "</form>";
  116.     }
  117.  
  118.     function HTMLEditorHandler(){
  119.         if ($_POST['new_page']) {
  120.             print "<h2>Create new page</h2>\n";
  121.             $this->EditForm(true);
  122.         } else if($_POST['edit']){
  123.             print "<h2>Edit page</h2>\n";
  124.             $this->EditForm(false);
  125.         } else if($_POST['delete']){
  126.             $this->DeletePage();
  127.             $this->DefaultForm();
  128.         } else if($_POST['save']){
  129.             $this->SaveChanges($_POST['author'], $_POST['org_id'], $_POST['title'], $_POST['content'],$this->isNew);
  130.             $this->DefaultForm();
  131.         } else {
  132.             $this->DefaultForm();
  133.         }
  134.     }
  135. }
  136.  
  137. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement