Changed all smaller forms and tables to be uniform. Copyright notes.
[fa-stable.git] / sales / manage / sales_people.php
index 7d5e57b3e040c539e4e8e6fa253b7b12e669e2c4..bf4899e59f84da66c43b766915c505b0eab4c3b7 100644 (file)
@@ -1,5 +1,14 @@
 <?php
-
+/**********************************************************************
+    Copyright (C) FrontAccounting, LLC.
+       Released under the terms of the GNU Affero General Public License,
+       AGPL, as published by the Free Software Foundation, either version 
+       3 of the License, or (at your option) any later version.
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+    See the License here <http://www.gnu.org/licenses/agpl-3.0.html>.
+***********************************************************************/
 $page_security = 3;
 $path_to_root="../..";
 include($path_to_root . "/includes/session.inc");
@@ -8,18 +17,10 @@ page(_("Sales Persons"));
 
 include($path_to_root . "/includes/ui.inc");
 
-if (isset($_GET['selected_id']))
-{
-       $selected_id = strtoupper($_GET['selected_id']);
-}
-elseif (isset($_POST['selected_id']))
-{
-       $selected_id = strtoupper($_POST['selected_id']);
-}
-
+simple_page_mode(true);
 //------------------------------------------------------------------------------------------------
 
-if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
+if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
 {
 
        //initialise no input errors assumed initially before we test
@@ -29,6 +30,7 @@ if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
        {
                $input_error = 1;
                display_error(_("The sales person name cannot be empty."));
+               set_focus('salesman_name');
        }
        $pr1 = check_num('provision', 0,100);
        if (!$pr1 || !check_num('provision2', 0, 100)) {
@@ -43,7 +45,7 @@ if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
        }
        if ($input_error != 1)
        {
-       if (isset($selected_id))
+       if ($selected_id != -1) 
        {
                /*selected_id 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*/
 
@@ -70,12 +72,15 @@ if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
        }
 
        //run the sql from either of the above possibilites
-       db_query($sql,"The insert or update of the salesperson failed");
-
-               meta_forward($_SERVER['PHP_SELF']);
+       db_query($sql,"The insert or update of the sales person failed");
+       if ($selected_id != -1) 
+                       display_notification(_('Selected sales person data have been updated'));
+               else
+                       display_notification(_('New sales person data have been added'));
+               $Mode = 'RESET';
        }
 }
-if (isset($_GET['delete']))
+if ($Mode == 'Delete')
 {
        //the link to delete a selected record was clicked instead of the submit button
 
@@ -92,16 +97,22 @@ if (isset($_GET['delete']))
        {
                $sql="DELETE FROM ".TB_PREF."salesman WHERE salesman_code='$selected_id'";
                db_query($sql,"The sales-person could not be deleted");
-
-               meta_forward($_SERVER['PHP_SELF']);
+               display_notification(_('Selected sales person data have been deleted'));
        }
+       $Mode = 'RESET';
 }
 
+if ($Mode == 'RESET')
+{
+       $selected_id = -1;
+       unset($_POST);
+}
 //------------------------------------------------------------------------------------------------
 
 $sql = "SELECT * FROM ".TB_PREF."salesman";
 $result = db_query($sql,"could not get sales persons");
 
+start_form();
 start_table("$table_style width=60%");
 $th = array(_("Name"), _("Phone"), _("Fax"), _("Email"), _("Provision"), _("Break Pt."), _("Provision")." 2", "", "");
 table_header($th);
@@ -116,57 +127,62 @@ while ($myrow = db_fetch($result))
     label_cell($myrow["salesman_name"]);
        label_cell($myrow["salesman_phone"]);
        label_cell($myrow["salesman_fax"]);
-       label_cell($myrow["salesman_email"]);
+       email_cell($myrow["salesman_email"]);
        label_cell(percent_format($myrow["provision"])." %", "nowrap align=right");
        amount_cell($myrow["break_pt"]);
        label_cell(percent_format($myrow["provision2"])." %", "nowrap align=right");
-       edit_link_cell(SID . "selected_id=" . $myrow["salesman_code"]);
-       delete_link_cell(SID . "selected_id=" . $myrow["salesman_code"]. "&delete=1");
+       edit_button_cell("Edit".$myrow["salesman_code"], _("Edit"));
+       delete_button_cell("Delete".$myrow["salesman_code"], _("Delete"));
        end_row();
 
 } //END WHILE LIST LOOP
 
 end_table();
-
-//------------------------------------------------------------------------------------------------
-
-hyperlink_no_params($_SERVER['PHP_SELF'], _("New Sales Person"));
+end_form();
+echo '<br>';
 
 //------------------------------------------------------------------------------------------------
 
 start_form();
 
-if (isset($selected_id))
-{
-       //editing an existing Sales-person
-       $sql = "SELECT *  FROM ".TB_PREF."salesman WHERE salesman_code='$selected_id'";
-
-       $result = db_query($sql,"could not get sales person");
-       $myrow = db_fetch($result);
-
-       $_POST['salesman_name'] = $myrow["salesman_name"];
-       $_POST['salesman_phone'] = $myrow["salesman_phone"];
-       $_POST['salesman_fax'] = $myrow["salesman_fax"];
-       $_POST['salesman_email'] = $myrow["salesman_email"];
-       $_POST['provision'] = percent_format($myrow["provision"]);
-       $_POST['break_pt'] = price_format($myrow["break_pt"]);
-       $_POST['provision2'] = percent_format($myrow["provision2"]);
 
+$_POST['salesman_email'] = "";
+if ($selected_id != -1) 
+{
+       if ($Mode == 'Edit') {
+               //editing an existing Sales-person
+               $sql = "SELECT *  FROM ".TB_PREF."salesman WHERE salesman_code='$selected_id'";
+
+               $result = db_query($sql,"could not get sales person");
+               $myrow = db_fetch($result);
+
+               $_POST['salesman_name'] = $myrow["salesman_name"];
+               $_POST['salesman_phone'] = $myrow["salesman_phone"];
+               $_POST['salesman_fax'] = $myrow["salesman_fax"];
+               $_POST['salesman_email'] = $myrow["salesman_email"];
+               $_POST['provision'] = percent_format($myrow["provision"]);
+               $_POST['break_pt'] = price_format($myrow["break_pt"]);
+               $_POST['provision2'] = percent_format($myrow["provision2"]);
+       }
        hidden('selected_id', $selected_id);
+} elseif ($Mode != 'ADD_ITEM') {
+               $_POST['provision'] = percent_format(0);
+               $_POST['break_pt'] = price_format(0);
+               $_POST['provision2'] = percent_format(0);       
 }
 
-start_table("$table_style2 width=60%");
+start_table($table_style2);
 
 text_row_ex(_("Sales person name:"), 'salesman_name', 30);
 text_row_ex(_("Telephone number:"), 'salesman_phone', 20);
 text_row_ex(_("Fax number:"), 'salesman_fax', 20);
-text_row_ex(_("Email:"), 'salesman_email', 40);
-percent_row(_("Provision"), 'provision');
+email_row_ex(_("E-mail:"), 'salesman_email', 40);
+percent_row(_("Provision").':', 'provision');
 amount_row(_("Break Pt.:"), 'break_pt');
-percent_row(_("Provision")." 2", 'provision2');
+percent_row(_("Provision")." 2:", 'provision2');
 end_table(1);
 
-submit_add_or_update_center(!isset($selected_id));
+submit_add_or_update_center($selected_id == -1, '', true);
 
 end_form();