- modules/fotolab updated imagej to current version & some cod fixes to make it work
[care2x.git] / Care2007 / modules / weberp / Areas.php
blob32f0bf9a254a12a47de564700bfca05272255765
1 <?php
2 /* $Revision: 1.10 $ */
3 $PageSecurity = 3;
5 include('includes/session.inc');
7 $title = _('Sales Area Maintenance');
9 include('includes/header.inc');
12 if (isset($_GET['SelectedArea'])){
13 $SelectedArea = strtoupper($_GET['SelectedArea']);
14 } elseif (isset($_POST['SelectedArea'])){
15 $SelectedArea = strtoupper($_POST['SelectedArea']);
18 if (isset($_POST['submit'])) {
20 //initialise no input errors assumed initially before we test
21 $InputError = 0;
23 /* actions to take once the user has clicked the submit button
24 ie the page has called itself with some user input */
26 //first off validate inputs sensible
27 $_POST['AreaCode'] = strtoupper($_POST['AreaCode']);
28 // mod to handle 3 char area codes
29 if (strlen($_POST['AreaCode']) > 3) {
30 $InputError = 1;
31 prnMsg(_('The area code must be three characters or less long'),'error');
32 } elseif (strlen($_POST['AreaDescription']) >25) {
33 $InputError = 1;
34 prnMsg(_('The area description must be twenty five characters or less long'),'error');
35 } elseif ( trim($_POST['AreaCode']) == '' ) {
36 $InputError = 1;
37 prnMsg(_('The area code may not be empty'),'error');
38 } elseif ( trim($_POST['AreaDescription']) == '' ) {
39 $InputError = 1;
40 prnMsg(_('The area description may not be empty'),'error');
43 if ($SelectedArea AND $InputError !=1) {
45 /*SelectedArea could also exist if submit had not been clicked this code would not run in this case cos submit is false of course see the delete code below*/
47 $sql = "UPDATE areas SET
48 areacode='" . $_POST['AreaCode'] . "',
49 areadescription='" . $_POST['AreaDescription'] . "'
50 WHERE areacode = '$SelectedArea'";
52 $msg = _('Area code') . ' ' . $SelectedArea . ' ' . _('has been updated');
54 } elseif ($InputError !=1) {
56 /*Selectedarea is null cos no item selected on first time round so must be adding a record must be submitting new entries in the new area form */
58 $sql = "INSERT INTO areas (areacode,
59 areadescription)
60 VALUES (
61 '" . $_POST['AreaCode'] . "',
62 '" . $_POST['AreaDescription'] . "'
63 )";
65 $SelectedArea =$_POST['AreaCode'];
66 $msg = _('New area code') . ' ' . $_POST['AreaCode'] . ' ' . _('has been inserted');
69 //run the SQL from either of the above possibilites
70 $ErrMsg = _('The area could not be added or updated because');
71 $DbgMsg = _('The SQL that failed was');
72 $result = DB_query($sql, $db, $ErrMsg, $DbgMsg);
73 if ($InputError !=1) {
74 unset($SelectedArea);
75 unset($_POST['AreaCode']);
76 unset($_POST['AreaDescription']);
79 prnMsg($msg,'success');
81 } elseif (isset($_GET['delete'])) {
82 //the link to delete a selected record was clicked instead of the submit button
84 $CancelDelete = 0;
86 // PREVENT DELETES IF DEPENDENT RECORDS IN 'DebtorsMaster'
88 $sql= "SELECT COUNT(*) FROM custbranch WHERE custbranch.area='$SelectedArea'";
89 $result = DB_query($sql,$db);
90 $myrow = DB_fetch_row($result);
91 if ($myrow[0]>0) {
92 $CancelDelete = 1;
93 prnMsg( _('Cannot delete this area because customer branches have been created using this area'),'warn');
94 echo '<br>' . _('There are') . ' ' . $myrow[0] . ' ' . _('branches using this area code');
96 } else {
97 $sql= "SELECT COUNT(*) FROM salesanalysis WHERE salesanalysis.area ='$SelectedArea'";
98 $result = DB_query($sql,$db);
99 $myrow = DB_fetch_row($result);
100 if ($myrow[0]>0) {
101 $CancelDelete = 1;
102 prnMsg( _('Cannot delete this area because sales analysis ecords exist that use this area'),'warn');
103 echo '<br>' . _('There are') . ' ' . $myrow[0] . ' ' . _('sales analysis records referring this area code');
107 if ($CancelDelete==0) {
108 $sql="DELETE FROM areas WHERE areacode='" . $SelectedArea . "'";
109 $result = DB_query($sql,$db);
110 prnMsg(_('Area Code') . ' ' . $SelectedArea . ' ' . _('has been deleted') .' !','success');
111 } //end if Delete area
112 unset($SelectedArea);
113 unset($_GET['delete']);
116 if (!isset($SelectedArea)) {
118 $sql = 'SELECT * FROM areas';
119 $result = DB_query($sql,$db);
121 echo '<CENTER><table border=1>';
122 echo "<tr>
123 <td class='tableheader'>" . _('Area Code') . "</td>
124 <td class='tableheader'>" . _('Area Name') . '</td>';
126 $k=0; //row colour counter
128 while ($myrow = DB_fetch_row($result)) {
129 if ($k==1){
130 echo "<tr bgcolor='#CCCCCC'>";
131 $k=0;
132 } else {
133 echo "<tr bgcolor='#EEEEEE'>";
134 $k++;
137 echo '<TD>' . $myrow[0] . '</TD>';
138 echo '<TD>' . $myrow[1] . '</TD>';
139 echo '<TD><A HREF="' . $_SERVER['PHP_SELF'] . '?' . SID . '&SelectedArea=' . $myrow[0] . '">' . _('Edit') . '</A></TD>';
140 echo '<TD><A HREF="' . $_SERVER['PHP_SELF'] . '?' . SID . '&SelectedArea=' . $myrow[0] . '&delete=yes">' . _('Delete') . '</A></TD>';
143 //END WHILE LIST LOOP
144 echo '</TABLE></CENTER>';
147 //end of ifs and buts!
149 if (isset($SelectedArea)) {
150 echo "<CENTER><A HREF='" . $_SERVER['PHP_SELF'] . '?' . SID . "'>" . _('Review Areas Defined') . '</A></CENTER>';
154 if (!isset($_GET['delete'])) {
156 echo "<FORM METHOD='post' action=" . $_SERVER['PHP_SELF'] . '?' . SID . '>';
158 if ($SelectedArea) {
159 //editing an existing area
161 $sql = "SELECT areacode,
162 areadescription
163 FROM areas
164 WHERE areacode='$SelectedArea'";
166 $result = DB_query($sql, $db);
167 $myrow = DB_fetch_array($result);
169 $_POST['AreaCode'] = $myrow['areacode'];
170 $_POST['AreaDescription'] = $myrow['areadescription'];
172 echo "<INPUT TYPE=HIDDEN NAME=SelectedArea VALUE=" . $SelectedArea . '>';
173 echo '<INPUT TYPE=HIDDEN NAME=AreaCode VALUE=' .$_POST['AreaCode'] . '>';
174 echo '<CENTER><TABLE><TR><TD>' . _('Area Code') . ':</TD><TD>' . $_POST['AreaCode'] . '</TD></TR>';
176 } else {
177 echo '<CENTER><TABLE>
178 <TR>
179 <TD>' . _('Area Code') . ":</TD>
180 <TD><input type='Text' name='AreaCode' value='" . $_POST['AreaCode'] . "' SIZE=3 MAXLENGTH=3></TD>
181 </TR>";
184 echo '<TR><TD>' . _('Area Name') . ":</TD>
185 <TD><input type='Text' name='AreaDescription' value='" . $_POST['AreaDescription'] ."' SIZE=26 MAXLENGTH=25></TD>
186 </TR>
187 </TABLE>";
189 echo "<CENTER><input type='Submit' name='submit' value=" . _('Enter Information') .">
190 </FORM>";
192 } //end if record deleted no point displaying form to add record
194 include('includes/footer.inc');