1<?php 2 3include('includes/session.php'); 4$Title = _('Maintenance Of Petty Cash Type of Tabs'); 5/* webERP manual links before header.php */ 6$ViewTopic = 'PettyCash'; 7$BookMark = 'PCTabTypes'; 8include('includes/header.php'); 9echo '<p class="page_title_text"> 10 <img src="', $RootPath, '/css/', $_SESSION['Theme'], '/images/money_add.png" title="', _('Payment Entry'), '" alt="" />', ' ', $Title, ' 11 </p>'; 12if (isset($_POST['SelectedTab'])) { 13 $SelectedTab = mb_strtoupper($_POST['SelectedTab']); 14} elseif (isset($_GET['SelectedTab'])) { 15 $SelectedTab = mb_strtoupper($_GET['SelectedTab']); 16} 17if (isset($_POST['submit'])) { 18 /* actions to take once the user has clicked the submit button 19 ie the page has called itself with some user input */ 20 //first off validate inputs sensible 21 $InputError = 0; 22 if ($_POST['TypeTabCode'] == '') { 23 $InputError = 1; 24 prnMsg(_('The Tabs type code cannot be an empty string'), 'error'); 25 } elseif (mb_strlen($_POST['TypeTabCode']) > 20) { 26 $InputError = 1; 27 echo prnMsg(_('The tab code must be twenty characters or less long'), 'error'); 28 } elseif (ContainsIllegalCharacters($_POST['TypeTabCode']) or mb_strpos($_POST['TypeTabCode'], ' ') > 0) { 29 $InputError = 1; 30 prnMsg(_('The petty cash tab type code cannot contain any of the illegal characters'), 'error'); 31 } elseif (mb_strlen($_POST['TypeTabDescription']) > 50) { 32 $InputError = 1; 33 echo prnMsg(_('The tab code must be Fifty characters or less long'), 'error'); 34 } 35 if (isset($SelectedTab) and $InputError != 1) { 36 $SQL = "UPDATE pctypetabs 37 SET typetabdescription = '" . $_POST['TypeTabDescription'] . "' 38 WHERE typetabcode = '" . $SelectedTab . "'"; 39 $Msg = _('The Tabs type') . ' ' . $SelectedTab . ' ' . _('has been updated'); 40 } elseif ($InputError != 1) { 41 // First check the type is not being duplicated 42 $checkSql = "SELECT count(*) 43 FROM pctypetabs 44 WHERE typetabcode = '" . $_POST['TypeTabCode'] . "'"; 45 $checkresult = DB_query($checkSql); 46 $checkrow = DB_fetch_row($checkresult); 47 if ($checkrow[0] > 0) { 48 $InputError = 1; 49 prnMsg(_('The Tab type ') . $_POST['TypeAbbrev'] . _(' already exist.'), 'error'); 50 } else { 51 // Add new record on submit 52 $SQL = "INSERT INTO pctypetabs 53 (typetabcode, 54 typetabdescription) 55 VALUES ('" . $_POST['TypeTabCode'] . "', 56 '" . $_POST['TypeTabDescription'] . "')"; 57 $Msg = _('Tabs type') . ' ' . $_POST['TypeTabCode'] . ' ' . _('has been created'); 58 } 59 } 60 if ($InputError != 1) { 61 //run the SQL from either of the above possibilites 62 $Result = DB_query($SQL); 63 prnMsg($Msg, 'success'); 64 echo '<br />'; 65 unset($SelectedTab); 66 unset($_POST['TypeTabCode']); 67 unset($_POST['TypeTabDescription']); 68 } 69} elseif (isset($_GET['delete'])) { 70 // PREVENT DELETES IF DEPENDENT RECORDS IN 'PcTabExpenses' 71 $SQLPcTabExpenses = "SELECT COUNT(*) 72 FROM pctabexpenses 73 WHERE typetabcode='" . $SelectedTab . "'"; 74 $ErrMsg = _('The number of tabs using this Tab type could not be retrieved'); 75 $ResultPcTabExpenses = DB_query($SQLPcTabExpenses, $ErrMsg); 76 $MyRowPcTabExpenses = DB_fetch_row($ResultPcTabExpenses); 77 $SqlPcTabs = "SELECT COUNT(*) 78 FROM pctabs 79 WHERE typetabcode='" . $SelectedTab . "'"; 80 $ErrMsg = _('The number of tabs using this Tab type could not be retrieved'); 81 $ResultPcTabs = DB_query($SqlPcTabs, $ErrMsg); 82 $MyRowPcTabs = DB_fetch_row($ResultPcTabs); 83 if ($MyRowPcTabExpenses[0] > 0 or $MyRowPcTabs[0] > 0) { 84 prnMsg(_('Cannot delete this tab type because tabs have been created using this tab type'), 'error'); 85 echo '<form method="post" action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '">'; 86 echo '<input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" />'; 87 echo '<div class="centre"><input type="submit" name="Return" value="', _('Return to list of tab types'), '" /></div>'; 88 echo '</form>'; 89 include('includes/footer.php'); 90 exit; 91 } else { 92 $SQL = "DELETE FROM pctypetabs WHERE typetabcode='" . $SelectedTab . "'"; 93 $ErrMsg = _('The Tab Type record could not be deleted because'); 94 $Result = DB_query($SQL, $ErrMsg); 95 prnMsg(_('Tab type') . ' ' . $SelectedTab . ' ' . _('has been deleted'), 'success'); 96 unset($SelectedTab); 97 unset($_GET['delete']); 98 } //end if tab type used in transactions 99} 100if (!isset($SelectedTab)) { 101 /* It could still be the second time the page has been run and a record has been selected for modification - SelectedTab will exist because it was sent with the new call. If its the first time the page has been displayed with no parameters 102 then none of the above are true and the list of sales types will be displayed with 103 links to delete or edit each. These will call the same page again and allow update/input 104 or deletion of the records*/ 105 $SQL = "SELECT typetabcode, 106 typetabdescription 107 FROM pctypetabs"; 108 $Result = DB_query($SQL); 109 echo '<table class="selection"> 110 <tr> 111 <th>', _('Type Of Tab'), '</th> 112 <th>', _('Description'), '</th> 113 </tr>'; 114 115 while ($MyRow = DB_fetch_array($Result)) { 116 echo '<tr class="striped_row"> 117 <td>', $MyRow['typetabcode'], '</td> 118 <td>', $MyRow['typetabdescription'], '</td> 119 <td><a href="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '?SelectedTab=', $MyRow['typetabcode'], '">' . _('Edit') . '</a></td> 120 <td><a href="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '?SelectedTab=', $MyRow['typetabcode'], '&delete=yes" onclick="return confirm(\'' . _('Are you sure you wish to delete this code and all the description it may have set up?') . '\', \'Confirm Delete\', this);">' . _('Delete') . '</a></td> 121 </tr>'; 122 } 123 //END WHILE LIST LOOP 124 echo '</table>'; 125} 126//end of ifs and buts! 127if (isset($SelectedTab)) { 128 echo '<div class="centre"> 129 <a href="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '">', _('Show All Types Tabs Defined'), '</a> 130 </div>'; 131} 132if (!isset($_GET['delete'])) { 133 echo '<form method="post" action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '">'; 134 echo '<input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" />'; 135 if (isset($SelectedTab) and $SelectedTab != '') { 136 $SQL = "SELECT typetabcode, 137 typetabdescription 138 FROM pctypetabs 139 WHERE typetabcode='" . $SelectedTab . "'"; 140 $Result = DB_query($SQL); 141 $MyRow = DB_fetch_array($Result); 142 $_POST['TypeTabCode'] = $MyRow['typetabcode']; 143 $_POST['TypeTabDescription'] = $MyRow['typetabdescription']; 144 echo '<input type="hidden" name="SelectedTab" value="', $SelectedTab, '" /> 145 <input type="hidden" name="TypeTabCode" value="', $_POST['TypeTabCode'], '" /> 146 <table class="selection"> 147 <tr> 148 <td>', _('Code Of Type Of Tab'), ':</td> 149 <td>', $_POST['TypeTabCode'], '</td> 150 </tr>'; 151 // We dont allow the user to change an existing type code 152 } else { 153 // This is a new type so the user may volunteer a type code 154 echo '<table class="selection"> 155 <tr> 156 <td>', _('Code Of Type Of Tab'), ':</td> 157 <td><input type="text" minlegth="1" maxlength="20" name="TypeTabCode" /></td> 158 </tr>'; 159 } 160 if (!isset($_POST['TypeTabDescription'])) { 161 $_POST['TypeTabDescription'] = ''; 162 } 163 echo '<tr> 164 <td>', _('Description Of Type of Tab'), ':</td> 165 <td><input type="text" name="TypeTabDescription" size="50" required="required" maxlength="50" value="', $_POST['TypeTabDescription'], '" /></td> 166 </tr>'; 167 echo '</table>'; // close main table 168 echo '<div class="centre"> 169 <input type="submit" name="submit" value="', _('Accept'), '" /> 170 <input type="submit" name="Cancel" value="', _('Cancel'), '" /> 171 </div> 172 </form>'; 173} // end if user wish to delete 174include('includes/footer.php'); 175?>