4 include($path_to_root . "/includes/session.inc");
5 include($path_to_root . "/admin/db/printers_db.inc");
6 include($path_to_root . "/includes/ui.inc");
8 page(_("Printing Profiles"));
10 $selected_id = get_post('profile_id','');
12 //-------------------------------------------------------------------------------------------------
13 // Returns array of defined reports
15 function get_reports() {
16 global $path_to_root, $comp_path, $go_debug;
18 if ($go_debug || !isset($_SESSION['reports'])) {
19 // to save time, store in session.
21 $path_to_root.'/reporting/',
22 $comp_path .'/'. user_company() . '/reporting/');
23 $reports = array( '' => _('Default printing destination'));
25 foreach($paths as $dirno => $path) {
26 $repdir = opendir($path);
27 while(false !== ($fname = readdir($repdir)))
29 // reports have filenames in form rep(repid).php
30 // where repid must contain at least one digit (reports_main.php is not ;)
31 if (is_file($path.$fname)
32 // && preg_match('/.*[^0-9]([0-9]+)[.]php/', $fname, $match))
33 && preg_match('/rep(.*[0-9]+.*)[.]php/', $fname, $match))
38 $line = file_get_contents($path.$fname);
39 if (preg_match('/.*(FrontReport\()\s*_\([\'"]([^\'"]*)/', $line, $match)) {
40 $title = trim($match[2]);
42 else // for any 3rd party printouts without FrontReport() class use
43 if (preg_match('/.*(\$Title).*[\'"](.*)[\'"].+/', $line, $match)) {
44 $title = trim($match[2]);
46 $reports[$repno] = $title;
52 $_SESSION['reports'] = $reports;
54 return $_SESSION['reports'];
59 global $selected_id, $Ajax;
63 $Ajax->activate('_page_body');
66 function check_delete($name)
68 // check if selected profile is used by any user
69 if ($name=='') return 0; // cannot delete system default profile
70 $sql = "SELECT * FROM ".TB_PREF."users WHERE print_profile='$name'";
71 $res = db_query($sql,'cannot check printing profile usage');
72 return db_num_rows($res);
74 //-------------------------------------------------------------------------------------------
75 if ( get_post('submit'))
80 if ($_POST['profile_id'] == '' && empty($_POST['name']))
83 display_error( _("Printing profile name cannot be empty."));
89 $prof = array('' => get_post('Prn')); // store default value/profile name
90 foreach (get_reports() as $rep => $descr) {
91 $val = get_post('Prn'.$rep);
94 if ($_POST['profile_id']=='')
95 $_POST['profile_id'] = get_post('name');
97 update_printer_profile($_POST['profile_id'], $prof);
98 if ($selected_id == '') {
99 display_notification_centered(_('New printing profile has been created'));
102 display_notification_centered(_('Printing profile has been updated'));
107 if(get_post('delete'))
109 if (!check_delete(get_post('name'))) {
110 delete_printer_profile($selected_id);
111 display_notification(_('Selected printing profile has been deleted'));
116 if(get_post('_profile_id_update')) {
117 $Ajax->activate('_page_body');
122 print_profiles_list_row(_('Select printing profile'). ':', 'profile_id', null,
123 _('New printing profile'), true);
127 if (get_post('profile_id') == '')
128 text_row(_("Printing Profile Name").':', 'name', null, 30, 30);
130 label_cells(_("Printing Profile Name").':', get_post('profile_id'));
133 $result = get_print_profile(get_post('profile_id'));
135 while ($myrow = db_fetch($result)) {
136 $prints[$myrow['report']] = $myrow['printer'];
139 start_table($table_style);
140 $th = array(_("Report Id"), _("Description"), _("Printer"));
145 foreach(get_reports() as $rep => $descr)
147 alt_table_row_color($k);
149 label_cell($rep=='' ? '-' : $rep, 'align=center');
150 label_cell($descr == '' ? '???<sup>1)</sup>' : _($descr));
151 $_POST['Prn'.$rep] = isset($prints[$rep]) ? $prints[$rep] : '';
153 printers_list('Prn'.$rep, null,
154 $rep == '' ? _('Browser support') : _('Default'));
156 if ($descr == '') $unkn = 1;
161 display_note('<sup>1)</sup> - '._("no title was found in this report definition file."), 0, 1, '');
165 div_start('controls');
166 if (get_post('profile_id') == '') {
167 submit_center('submit', _("Add New Profile"), true, '', true);
169 submit_center_first('submit', _("Update Profile"),
170 _('Update printer profile'), true);
171 submit_center_last('delete', _("Delete Profile"),
172 _('Delete printer profile (only if not used by any user)'), true);