Changeset 765 for trunk/includes/Page.php
- Timestamp:
- Jan 27, 2014, 10:01:33 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/Page.php
r639 r765 31 31 var $Table; 32 32 var $Definition; 33 var $ItemActions; 33 34 34 35 function __construct($System) … … 37 38 $this->Table = ''; 38 39 $this->Definition = array(); 40 $this->ItemActions = array( 41 array('Name' => T('View'), 'URL' => '?action=view&id=#Id'), 42 array('Name' => T('Delete'), 'URL' => '?action=remove&id=#Id'), 43 ); 39 44 } 40 45 … … 46 51 if($_GET['action'] == 'add') $Output .= $this->AddItem(); 47 52 else if($_GET['action'] == 'view') $Output .= $this->ViewItem(); 53 else if($_GET['action'] == 'edit') $Output .= $this->ModifyItem(); 48 54 else if($_GET['action'] == 'remove') $Output .= $this->RemoveItem(); 49 55 else if($_GET['action'] == 'delete') $Output .= $this->DeleteItem(); … … 55 61 function ViewItem() 56 62 { 57 $Output = ''; 58 return($Output); 63 $DbResult = $this->Database->query('SELECT * FROM ('.$this->TableSQL.') AS `T` WHERE `Id`='.$_GET['id']); 64 if($DbResult->num_rows > 0) 65 { 66 $DbRow = $DbResult->fetch_assoc(); 67 68 $Output = T('Item'). 69 '<table>'; 70 foreach($this->Definition as $DefIndex => $Def) 71 { 72 $Output .= '<tr><td>'.$Def['Title'].':</td><td>'.$this->ViewControl($Def['Type'], $DefIndex, $DbRow[$DefIndex]).'</tr>'; 73 } 74 $Output .= '<tr>'. 75 '</table>'; 76 } else $Output = ShowMessage(T('Item not found'), MESSAGE_CRITICAL); 77 $Output .= '<a href="?action=add">'.T('Add').'</a> '; 78 $Output .= '<a href="?action=edit&id='.$_GET['id'].'">'.T('Edit').'</a> '; 79 $Output .= '<a href="?action=delete&id='.$_GET['id'].'">'.T('Add').'</a> '; 80 $Output .= '<a href="?">'.T('List').'</a><br/>'; 81 return($Output); 59 82 } 60 83 … … 69 92 $TableColumns = array(); 70 93 foreach($this->Definition as $Index => $Def) 71 $TableColumns[] = array('Name' => $Index, 'Title' => $Def['Title']); 94 if($Def['InList']) 95 $TableColumns[] = array('Name' => $Index, 'Title' => $Def['Title']); 96 if(count($this->ItemActions) > 0) 97 $TableColumns[] = array('Name' => '', 'Title' => 'Akce'); 72 98 73 99 $Order = GetOrderTableHeader($TableColumns, 'Name', 0); … … 79 105 $Output .= '<tr>'; 80 106 foreach($this->Definition as $Index => $Def) 107 if($Def['InList']) 81 108 { 82 109 if($Def['Type'] == 'URL') $Output .= '<td><a href="'.$Item[$Index].'">'.$Item[$Index].'</a></td>'; 83 110 else $Output .= '<td>'.$Item[$Index].'</td>'; 84 111 } 112 if(count($this->ItemActions) > 0) 113 { 114 $Output .= '<td>'; 115 foreach($this->ItemActions as $Index => $Action) 116 { 117 $URL = $Action['URL']; 118 if(strpos($URL, '#Id')) $URL = str_replace('#Id', $Item['Id'], $URL); 119 $Output .= '<a href="'.$URL.'">'.$Action['Name'].'</a> '; 120 } 121 $Output .= '</td>'; 122 } 85 123 $Output .= '</tr>'; 86 124 } 87 $Output .= '</table>'; 125 $Output .= '</table>'; 126 $Output .= '<a href="?action=add">'.T('Add').'</a><br/>'; 88 127 return($Output); 89 128 } … … 105 144 } else 106 145 { 107 $Output .= '<form action="?action=add&finish=1" method="post">'.108 '<fieldset><legend>'.T('New item').'</legend>'.109 '<table>';110 foreach($this->Definition as $DefIndex => $Def)111 {112 $Output .= '<tr><td>'.$Def['Title'].'</td><td>'.$this->GetControl($Def['Type'], $DefIndex).'</tr>';113 }114 $Output .= '<tr><td colspan="2"><input type="submit" value="'.T('Add').'" /></td></tr>'.115 '</table>'.116 '</fieldset>'.117 '</form>';146 $Output .= '<form action="?action=add&finish=1" method="post">'. 147 '<fieldset><legend>'.T('New item').'</legend>'. 148 '<table>'; 149 foreach($this->Definition as $DefIndex => $Def) 150 { 151 $Output .= '<tr><td>'.$Def['Title'].':</td><td>'.$this->GetControl($Def['Type'], $DefIndex, '').'</tr>'; 152 } 153 $Output .= '<tr><td colspan="2"><input type="submit" value="'.T('Add').'" /></td></tr>'. 154 '</table>'. 155 '</fieldset>'. 156 '</form>'; 118 157 } 119 158 } else $Output .= ShowMessage(T('Access denied'), MESSAGE_CRITICAL); 120 159 return($Output); 121 } 122 160 } 123 161 124 162 function DeleteItem() … … 132 170 } 133 171 134 function GetControl($Type, $Name )172 function GetControl($Type, $Name, $Value) 135 173 { 136 if($Type == 'Text') $Output = '<input type="text" name="'.$Name.'" />';174 if($Type == 'Text') $Output = '<input type="text" name="'.$Name.'" value="'.$Value.'"/>'; 137 175 else if($Type == 'Boolean') $Output = '<input type="checkbox" name="'.$Name.'"/>'; 138 else $Output = '<input type="text" name="'.$Name.'"/>'; 176 else $Output = '<input type="text" name="'.$Name.'" value="'.$Value.'"/>'; 177 return($Output); 178 } 179 180 function ViewControl($Type, $Name, $Value) 181 { 182 if($Type == 'Text') $Output = $Value; 183 else if($Type == 'URL') $Output = '<a href="'.$Value.'">'.$Value.'</a>'; 184 else if($Type == 'Boolean') $Output = $Value; 185 else $Output = $Value; 186 return($Output); 139 187 } 140 188 }
Note:
See TracChangeset
for help on using the changeset viewer.