Changeset 816 for trunk/includes/Page.php
- Timestamp:
- Feb 22, 2015, 11:20:50 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/Page.php
r768 r816 7 7 var $RawPage; 8 8 var $Title; 9 9 10 10 function __construct($System) 11 11 { … … 14 14 $this->RawPage = false; 15 15 } 16 17 18 19 20 } 21 16 17 function Show() 18 { 19 return(''); 20 } 21 22 22 function GetOutput() 23 { 24 25 23 { 24 $Output = $this->Show(); 25 return($Output); 26 26 } 27 27 } … … 29 29 class PageEdit extends Page 30 30 { 31 32 33 34 35 36 31 var $Table; 32 var $Definition; 33 var $ItemActions; 34 35 function __construct($System) 36 { 37 37 parent::__construct($System); 38 38 $this->Table = ''; … … 41 41 array('Name' => T('View'), 'URL' => '?action=view&id=#Id'), 42 42 ); 43 $this->AllowEdit = false; 43 $this->AllowEdit = false; 44 44 if($this->AllowEdit) $this->ItemActions[] = array('Name' => T('Delete'), 'URL' => '?action=remove&id=#Id'); 45 46 47 48 49 50 if(array_key_exists('action', $_GET))45 } 46 47 function Show() 48 { 49 $Output = ''; 50 if(array_key_exists('action', $_GET)) 51 51 { 52 if($_GET['action'] == 'add') $Output .= $this->AddItem(); 52 if($_GET['action'] == 'add') $Output .= $this->AddItem(); 53 53 else if($_GET['action'] == 'view') $Output .= $this->ViewItem(); 54 54 else if($_GET['action'] == 'edit') $Output .= $this->ModifyItem(); … … 56 56 else if($_GET['action'] == 'delete') $Output .= $this->DeleteItem(); 57 57 else $Output .= ShowMessage(T('Unknown action'), MESSAGE_CRITICAL); 58 } else $Output .= $this->ViewList(); 59 return($Output); 58 } else $Output .= $this->ViewList(); 59 return($Output); 60 60 } 61 61 62 62 function ViewItem() 63 63 { 64 65 66 67 64 $DbResult = $this->Database->query('SELECT * FROM ('.$this->TableSQL.') AS `T` WHERE `Id`='.$_GET['id']); 65 if($DbResult->num_rows > 0) 66 { 67 $DbRow = $DbResult->fetch_assoc(); 68 68 69 69 $Output = T('Item'). … … 71 71 foreach($this->Definition as $DefIndex => $Def) 72 72 { 73 74 } 73 $Output .= '<tr><td>'.$Def['Title'].':</td><td>'.$this->ViewControl($Def['Type'], $DefIndex, $DbRow[$DefIndex]).'</tr>'; 74 } 75 75 $Output .= '<tr>'. 76 76 '</table>'; 77 78 if($this->AllowEdit) 79 80 81 82 83 84 85 return($Output); 77 } else $Output = ShowMessage(T('Item not found'), MESSAGE_CRITICAL); 78 if($this->AllowEdit) 79 { 80 $Output .= '<a href="?action=add">'.T('Add').'</a> '; 81 $Output .= '<a href="?action=edit&id='.$_GET['id'].'">'.T('Edit').'</a> '; 82 $Output .= '<a href="?action=delete&id='.$_GET['id'].'">'.T('Add').'</a> '; 83 } 84 $Output .= '<a href="?">'.T('List').'</a><br/>'; 85 return($Output); 86 86 } 87 87 88 88 function ViewList() 89 89 { 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 90 $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$this->TableSQL.') AS `T`'); 91 $DbRow = $DbResult->fetch_row(); 92 $PageList = GetPageList($DbRow[0]); 93 $Output = $PageList['Output']; 94 95 $Output .= '<table class="BaseTable">'; 96 $TableColumns = array(); 97 foreach($this->Definition as $Index => $Def) 98 if($Def['InList']) 99 $TableColumns[] = array('Name' => $Index, 'Title' => $Def['Title']); 100 if(count($this->ItemActions) > 0) 101 $TableColumns[] = array('Name' => '', 'Title' => 'Akce'); 102 103 $Order = GetOrderTableHeader($TableColumns, 'Name', 0); 104 $Output .= $Order['Output']; 105 106 $DbResult = $this->Database->query('SELECT * FROM ('.$this->Table.') '.$Order['SQL'].$PageList['SQLLimit']); 107 while($Item = $DbResult->fetch_assoc()) 108 { 109 $Output .= '<tr>'; 110 110 foreach($this->Definition as $Index => $Def) 111 111 if($Def['InList']) 112 112 { 113 114 113 if($Def['Type'] == 'URL') $Output .= '<td><a href="'.$Item[$Index].'">'.$Item[$Index].'</a></td>'; 114 else $Output .= '<td>'.$Item[$Index].'</td>'; 115 115 } 116 116 if(count($this->ItemActions) > 0) 117 { 118 119 120 121 122 117 { 118 $Output .= '<td>'; 119 foreach($this->ItemActions as $Index => $Action) 120 { 121 $URL = $Action['URL']; 122 if(strpos($URL, '#Id')) $URL = str_replace('#Id', $Item['Id'], $URL); 123 123 $Output .= '<a href="'.$URL.'">'.$Action['Name'].'</a> '; 124 }124 } 125 125 $Output .= '</td>'; 126 126 } 127 $Output .= '</tr>'; 128 129 130 131 127 $Output .= '</tr>'; 128 } 129 $Output .= '</table>'; 130 if($this->AllowEdit) $Output .= '<a href="?action=add">'.T('Add').'</a><br/>'; 131 return($Output); 132 132 } 133 134 133 134 function AddItem() 135 135 { 136 136 $Output = ''; 137 137 if($this->System->User->Licence(LICENCE_USER)) 138 138 { 139 140 141 142 143 144 $Items[$Index] = $_POST[$Index];145 146 147 $Output = ShowMessage(T('Item added'), MESSAGE_INFORMATION);148 } else149 139 if(array_key_exists('finish', $_GET)) 140 { 141 $Items = array(); 142 foreach($this->Definition as $Index => $Def) 143 { 144 $Items[$Index] = $_POST[$Index]; 145 } 146 $this->Database->insert($this->Table, $Items); 147 $Output = ShowMessage(T('Item added'), MESSAGE_INFORMATION); 148 } else 149 { 150 150 $Output .= '<form action="?action=add&finish=1" method="post">'. 151 151 '<fieldset><legend>'.T('New item').'</legend>'. … … 153 153 foreach($this->Definition as $DefIndex => $Def) 154 154 { 155 156 } 155 $Output .= '<tr><td>'.$Def['Title'].':</td><td>'.$this->GetControl($Def['Type'], $DefIndex, '').'</tr>'; 156 } 157 157 $Output .= '<tr><td colspan="2"><input type="submit" value="'.T('Add').'" /></td></tr>'. 158 158 '</table>'. 159 159 '</fieldset>'. 160 160 '</form>'; 161 161 } 162 162 } else $Output .= ShowMessage(T('Access denied'), MESSAGE_CRITICAL); 163 return($Output); 164 } 165 166 163 return($Output); 164 } 165 166 function DeleteItem() 167 167 { 168 168 if($this->System->User->Licence(LICENCE_USER)) … … 173 173 return($Output); 174 174 } 175 175 176 176 function GetControl($Type, $Name, $Value) 177 177 { 178 179 180 181 182 } 178 if($Type == 'Text') $Output = '<input type="text" name="'.$Name.'" value="'.$Value.'"/>'; 179 else if($Type == 'Boolean') $Output = '<input type="checkbox" name="'.$Name.'"/>'; 180 else $Output = '<input type="text" name="'.$Name.'" value="'.$Value.'"/>'; 181 return($Output); 182 } 183 183 184 184 function ViewControl($Type, $Name, $Value) 185 185 { 186 187 188 189 190 191 } 186 if($Type == 'Text') $Output = $Value; 187 else if($Type == 'URL') $Output = '<a href="'.$Value.'">'.$Value.'</a>'; 188 else if($Type == 'Boolean') $Output = $Value; 189 else $Output = $Value; 190 return($Output); 191 } 192 192 }
Note:
See TracChangeset
for help on using the changeset viewer.