Feature 5388: Print Invoices (documents) list gets too long. Fixed by default 180...
[fa-stable.git] / admin / print_profiles.php
index 49a8723ffb768e6933c9fbae4429d861b8ef958e..534c5168cf19ed88bccaf6c55ba4e2161166ce9b 100644 (file)
@@ -1,21 +1,21 @@
 <?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 
-       of the License, or (at your option) any later version.
+       Released under the terms of the GNU General Public License, GPL, 
+       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>.
+    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
-$page_security = 15;
-$path_to_root="..";
+$page_security = 'SA_PRINTPROFILE';
+$path_to_root = "..";
 include($path_to_root . "/includes/session.inc");
 include($path_to_root . "/admin/db/printers_db.inc");
 include($path_to_root . "/includes/ui.inc");
 
-page(_("Printing Profiles"));
+page(_($help_context = "Printing Profiles"));
 
 $selected_id = get_post('profile_id','');
 
@@ -23,41 +23,40 @@ $selected_id = get_post('profile_id','');
 // Returns array of defined reports
 //
 function get_reports() {
-       global $path_to_root, $comp_path, $go_debug;
+       global $path_to_root, $SysPrefs;
 
-if ($go_debug || !isset($_SESSION['reports'])) {       
+       if ($SysPrefs->go_debug || !isset($_SESSION['reports'])) {      
        // to save time, store in session.
                $paths = array (
                        $path_to_root.'/reporting/',
-                       $comp_path .'/'. user_company() . '/reporting/');
+                       company_path(). '/reporting/');
                $reports = array( '' => _('Default printing destination'));
 
-       foreach($paths as $dirno => $path) {
-               $repdir = opendir($path);
-               while(false !== ($fname = readdir($repdir)))
-               {
-               // reports have filenames in form rep(repid).php 
-               // where repid must contain at least one digit (reports_main.php is not ;)
-                       if (is_file($path.$fname) 
-//                             && preg_match('/.*[^0-9]([0-9]+)[.]php/', $fname, $match))
-                               && preg_match('/rep(.*[0-9]+.*)[.]php/', $fname, $match))
+               foreach($paths as $dirno => $path) {
+                       $repdir = opendir($path);
+                       while(false !== ($fname = readdir($repdir)))
                        {
-                               $repno = $match[1];
-                               $title = '';
-
-                               $line = file_get_contents($path.$fname);
-                               if (preg_match('/.*(FrontReport\()\s*_\([\'"]([^\'"]*)/', $line, $match)) {
-                                       $title = trim($match[2]);
-                               }
-                               else // for any 3rd party printouts without FrontReport() class use
+                               // reports have filenames in form rep(repid).php 
+                               // where repid must contain at least one digit (reports_main.php is not ;)
+                               if (is_file($path.$fname) 
+                                       && preg_match('/rep(.*[0-9]+.*)[.]php/', $fname, $match))
+                               {
+                                       $repno = $match[1];
+                                       $title = '';
+
+                                       $line = file_get_contents($path.$fname);
+                                       if (preg_match('/.*(FrontReport\()\s*_\([\'"]([^\'"]*)/', $line, $match)) {
+                                               $title = trim($match[2]);
+                                       }
+                                       else // for any 3rd party printouts without FrontReport() class use
                                        if (preg_match('/.*(\$Title).*[\'"](.*)[\'"].+/', $line, $match)) {
                                                $title = trim($match[2]);
                                        }
-                               $reports[$repno] = $title;
+                                       $reports[$repno] = $title;
+                               }
                        }
+                       closedir();
                }
-       closedir();
-       }
                ksort($reports);
                $_SESSION['reports'] = $reports;
        }
@@ -75,11 +74,9 @@ function clear_form()
 
 function check_delete($name)
 {
-// check if selected profile is used by any user
+       // check if selected profile is used by any user
        if ($name=='') return 0; // cannot delete system default profile
-       $sql = "SELECT * FROM ".TB_PREF."users WHERE print_profile='$name'";
-       $res = db_query($sql,'cannot check printing profile usage');
-       return db_num_rows($res);
+       return key_in_foreign_table($name, 'users', 'print_profile');
 }
 //-------------------------------------------------------------------------------------------
 if ( get_post('submit'))
@@ -102,12 +99,12 @@ if ( get_post('submit'))
                        $prof[$rep] = $val;
                }
                if ($_POST['profile_id']=='')
-               $_POST['profile_id'] = get_post('name');
+                       $_POST['profile_id'] = get_post('name');
                
                update_printer_profile($_POST['profile_id'], $prof);
                if ($selected_id == '') {
                        display_notification_centered(_('New printing profile has been created')); 
-                       clear_form();
+                       clear_form($selected_id);
                } else {
                        display_notification_centered(_('Printing profile has been updated'));
                }
@@ -116,11 +113,11 @@ if ( get_post('submit'))
 
 if(get_post('delete'))
 {
- if (!check_delete(get_post('name'))) {
-       delete_printer_profile($selected_id);
-       display_notification(_('Selected printing profile has been deleted'));
-       clear_form();
- }
      if (!check_delete(get_post('name'))) {
+               delete_printer_profile($selected_id);
+               display_notification(_('Selected printing profile has been deleted'));
+               clear_form();
      }
 }
 
 if(get_post('_profile_id_update')) {
@@ -146,7 +143,7 @@ while ($myrow = db_fetch($result)) {
        $prints[$myrow['report']] = $myrow['printer'];
 }
 
-start_table($table_style);
+start_table(TABLESTYLE);
 $th = array(_("Report Id"), _("Description"), _("Printer"));
 table_header($th);
 
@@ -160,7 +157,7 @@ foreach(get_reports() as $rep => $descr)
     label_cell($descr == '' ? '???<sup>1)</sup>' : _($descr));
        $_POST['Prn'.$rep] = isset($prints[$rep]) ? $prints[$rep] : '';
     echo '<td>';
-       printers_list('Prn'.$rep, null, 
+       echo printers_list('Prn'.$rep, null, 
                $rep == '' ? _('Browser support') : _('Default'));
        echo '</td>';
        if ($descr == '') $unkn = 1;
@@ -174,10 +171,10 @@ else
 
 div_start('controls');
 if (get_post('profile_id') == '') {
-       submit_center('submit', _("Add New Profile"), true, '', true);
+       submit_center('submit', _("Add New Profile"), true, '', 'default');
 } else {
        submit_center_first('submit', _("Update Profile"), 
-         _('Update printer profile'), true);
+         _('Update printer profile'), 'default');
        submit_center_last('delete', _("Delete Profile"), 
          _('Delete printer profile (only if not used by any user)'), true);
 }
@@ -186,4 +183,3 @@ div_end();
 end_form();
 end_page();
 
-?>