diff --git a/.travis.yml b/.travis.yml index 98ebd9ceea3..f65d575f924 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ php: - "5.3" - "5.4" - "5.5" + - "5.6" env: - DB=mysql diff --git a/.tx/config b/.tx/config index e4d1fc65732..74875508f29 100644 --- a/.tx/config +++ b/.tx/config @@ -236,6 +236,18 @@ source_file = htdocs/langs/en_US/paypal.lang source_lang = en_US type = MOZILLAPROPERTIES +[dolibarr.printgcp] +file_filter = htdocs/langs//printgcp.lang +source_file = htdocs/langs/en_US/printgcp.lang +source_lang = en_US +type = MOZILLAPROPERTIES + +[dolibarr.printing] +file_filter = htdocs/langs//printing.lang +source_file = htdocs/langs/en_US/printing.lang +source_lang = en_US +type = MOZILLAPROPERTIES + [dolibarr.printipp] file_filter = htdocs/langs//printipp.lang source_file = htdocs/langs/en_US/printipp.lang diff --git a/COPYRIGHT b/COPYRIGHT index 2e1c6e921b9..c6a629c5c7a 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -52,6 +52,9 @@ http://www.fsf.org/licensing/licenses/index_html Copyright --------- +Copyright (C) 2015 +- Marcos García + Copyright (C) 2014 - Laurent Destailleur - Raphaël Doursenaud diff --git a/ChangeLog b/ChangeLog index c7c373ebaaf..9aae192541f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ -------------------------------------------------------------- English Dolibarr ChangeLog -------------------------------------------------------------- +***** ChangeLog for 3.8 compared to 3.7.* ***** +- New: Add Option to not change date on cloning project +- New: Add check list from table for extrafield type ***** ChangeLog for 3.8 compared to 3.7.* ***** @@ -8,7 +11,11 @@ For users: - New: Use new combobox. - New: Add hidden option MAXTABS_IN_CARD. - Fix / Improve : [ bug #1747 ] Remove creation of batch 'Undefined' - +- Add Weighted average price as default price for buying price for margin calculation. Add option + MARGIN_PMP_AS_DEFAULT_BUY_PRICE to replace with first supplier price. +- Introduce option MAIN_HTML_TITLE to start to control format of html title content. +- Add extrafields on bank account cards. +- Added delay between mails in Newsletter module For translators: - Update language files. @@ -188,6 +195,20 @@ Dolibarr better: ***** ChangeLog for 3.6.3 compared to 3.6.2 ***** - Fix: ref_ext was not saved when recording a customer order from web service +- Fix: amarok is a bugged theme making dolidroid failed. We swith to eldy automatically with dolidroid. +- Fix: withdrawal create error if in the same month are deleted previus withdrawals. +- Fix: [ bug #1788 ] Duplicated doActions hook in product/fournisseurs.php +- Fix: withdrawal create error if in the same month are deleted previus withdrawals. +- Fix: [ bug #1801 ] FAC_FORCE_DATE_VALIDATION constant alters supplier invoice date given to numeration modules +- Fix: [ bug #1802 ] SQL error when updating a task with PostgreSQL database +- Fix: [ bug #1785 ] Start date is lost in Project > Linked objects +- Fix: [ bug #1804 ] SQL error when sending email without addresee +- Fix: [ bug #1803 ] AJAX company contact input is not aligned +- Fix: [ bug #1787 ] Incorrect behaviour of doActions hook +- Fix: [ bug #1796 ] Unable to use numeration modules from an external module +- Fix: [ bug #1783 ] SQL error when enabling 3rd party module with PostgreSQL and MySQL strict mode ON +- Fix: [ bug #1717 ] Sorting unpaid invoices by amount received brings due amount +- Fix: [ bug #1784 ] MOTD doesn't show up in Amarok theme ***** ChangeLog for 3.6.2 compared to 3.6.1 ***** - Fix: fix ErrorBadValueForParamNotAString error message in price customer multiprice. @@ -352,6 +373,8 @@ Fix: Paypal link were broken dur to SSL v3 closed. Fix: [ bug #1769 ] Error when installing to a PostgreSQL DB that contains numbers Fix: [ bug #1752 ] Date filter of margins module, filters since 12H instead of 00H Fix: [ bug #1757 ] Sorting breaks product/service statistics +Fix: [ bug #1797 ] Tulip supplier invoice module takes creation date instead of invoice date +Fix: [ bug #1792 ] Users are not allowed to see margins module index page when no product view permission is enabled ***** ChangeLog for 3.5.6 compared to 3.5.5 ***** Fix: Avoid missing class error for fetch_thirdparty method #1973 diff --git a/build/makepack-howto.txt b/build/makepack-howto.txt index 40b0e5180bc..9e5004f4ba7 100644 --- a/build/makepack-howto.txt +++ b/build/makepack-howto.txt @@ -11,7 +11,6 @@ beta version of Dolibarr, step by step. - Update version/info in /ChangeLog - Update version number with x.y.z-w in htdocs/filefunc.inc.php - Update version number with x.y.z-w in build/debian/changelog -- Update version number with x.y.z-w in build/exe/doliwamp/doliwamp.iss - Update version number with x.y.z-w in build/rpm/*.spec - Commit all changes. - Add a Tag (x.y.betaz_YYYYMMDD) and push it: git push --tags @@ -30,10 +29,9 @@ This files describe steps made by Dolibarr packaging team to make a complete release of Dolibarr, step by step. - Check all files are commited. -- Update version/info in ChangeLog +- Update version/info in ChangeLog. To generate a changelog, you can do "git log x.y.z..HEAD --no-merges --pretty=short --oneline | sed -e "s/^[0-9a-z]* //" | grep -e '^Fix\|New\|Sec'" - Update version number with x.y.z in htdocs/filefunc.inc.php - Update version number with x.y.z in build/debian/changelog -- Update version number with x.y.z in build/exe/doliwamp/doliwamp.iss - Update version number with x.y.z in build/rpm/*.spec - Commit all changes. diff --git a/dev/codesniffer/ruleset.xml b/dev/codesniffer/ruleset.xml index 49af678ccff..6ee57ace8ef 100755 --- a/dev/codesniffer/ruleset.xml +++ b/dev/codesniffer/ruleset.xml @@ -253,14 +253,80 @@ 0 - - - - - - + + + 0 + + + 0 + + + 0 + + + 0 + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + 0 + + + 0 + + + 0 + + + 0 + + + + 0 + + + 0 + + + 0 + + + 0 + + +>>>>>>> refs/remotes/origin/3.7 diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index a3cac080ab5..0c345aee5ac 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -2,7 +2,9 @@ /* Copyright (C) 2010-2012 Regis Houssin * Copyright (C) 2010-2014 Laurent Destailleur * Copyright (C) 2012-2013 Christophe Battarel + * Copyright (C) 2012 Cédric Salvador * Copyright (C) 2013 Florian Henry + * Copyright (C) 2014 Raphaël Doursenaud * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -58,6 +60,9 @@ if (in_array($object->element,array('propal','facture','invoice','commande','ord trans('Qty'); ?> trans('ReductionShort'); ?> situation_cycle_ref) { + print '' . $langs->trans('Progress') . ''; + } if (! empty($usemargins)) { ?> @@ -214,8 +219,11 @@ else { "> remise_percent); ?>">% - situation_cycle_ref) { + $coldisplay++; + print '%'; + } if (! empty($usemargins)) { ?> @@ -277,6 +285,7 @@ if (! empty($conf->service->enabled) && $dateSelector && GETPOST('type') != '0') { if(! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) $colspan = 10; else $colspan = 9; + if($this->situation_cycle_ref) $colspan++; if (! empty($inputalsopricewithtax)) $colspan++; // We add 1 if col total ttc if (in_array($object->element,array('propal','facture','invoice','commande','order'))) $colspan++; // With this, there is a column move button @@ -483,7 +492,8 @@ jQuery(document).ready(function() { } if (this.id == 'pmpprice') { - if (this.price > 0 && 1 == 1) { defaultkey = this.id; defaultprice = this.price; } + var defaultbuyprice = global->MARGIN_PMP_AS_DEFAULT_BUY_PRICE)?int($conf->global->MARGIN_PMP_AS_DEFAULT_BUY_PRICE):1); ?>; + if (this.price > 0 && 1 == defaultbuyprice) { defaultkey = this.id; defaultprice = this.price; } options += ''; } }); diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index fbe2870a6a4..fd2e3e0d469 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -2,6 +2,8 @@ /* Copyright (C) 2010-2012 Regis Houssin * Copyright (C) 2010-2012 Laurent Destailleur * Copyright (C) 2012 Christophe Battarel + * Copyright (C) 2012 Cédric Salvador + * Copyright (C) 2012-2014 Raphaël Doursenaud * Copyright (C) 2013 Florian Henry * * This program is free software; you can redistribute it and/or modify @@ -83,22 +85,44 @@ $coldisplay=-1; // We remove first td $reshook=$hookmanager->executeHooks('formEditProductOptions',$parameters,$this,$action); } - // editeur wysiwyg - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $nbrows=ROWS_2; - if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT; - $enable=(isset($conf->global->FCKEDITOR_ENABLE_DETAILS)?$conf->global->FCKEDITOR_ENABLE_DETAILS:0); - $doleditor=new DolEditor('product_desc',$line->description,'',164,'dolibarr_details','',false,true,$enable,$nbrows,'98%'); - $doleditor->Create(); + // Do not allow editing during a situation cycle + if ($this->situation_counter == 1 || !$this->situation_cycle_ref) { + // editeur wysiwyg + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; + $nbrows=ROWS_2; + if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT; + $enable=(isset($conf->global->FCKEDITOR_ENABLE_DETAILS)?$conf->global->FCKEDITOR_ENABLE_DETAILS:0); + $doleditor=new DolEditor('product_desc',$line->description,'',164,'dolibarr_details','',false,true,$enable,$nbrows,'98%'); + $doleditor->Create(); + } else { + print ''; + } ?> - load_tva('tva_tx',$line->tva_tx,$seller,$buyer,0,$line->info_bits,$line->product_type); ?> + situation_counter == 1 || !$this->situation_cycle_ref) { + print '' . $form->load_tva('tva_tx',$line->tva_tx,$seller,$buyer,0,$line->info_bits,$line->product_type) . ''; + } else { + print '%'; + } - - - - + $coldisplay++; + print 'situation_counter > 1) { + print 'readonly="readonly" '; + } + print '>'; + + if ($inputalsopricewithtax) { + $coldisplay++; + print 'situation_counter > 1) { + print 'readonly="readonly" '; + } + print '>'; + } ?> info_bits & 2) != 2) { @@ -106,22 +130,32 @@ $coldisplay=-1; // We remove first td // for example always visible on invoice but must be visible only if stock module on and stock decrease option is on invoice validation and status is not validated // must also not be output for most entities (proposal, intervention, ...) //if($line->qty > $line->stock) print img_picto($langs->trans("StockTooLow"),"warning", 'style="vertical-align: bottom;"')." "; - ?> - - + print 'situation_counter > 1) { + print 'readonly="readonly" '; + } + print '/>'; + } else { ?>   - info_bits & 2) != 2) { ?> - % - + info_bits & 2) != 2) { + print 'situation_counter > 1) { + print 'readonly="readonly" '; + } + print '/>%'; + } else { ?>   - situation_cycle_ref) { + $coldisplay++; + print '%'; + } if (! empty($usemargins)) { ?> diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php index 3d2ea127b85..2e1cc0f3678 100644 --- a/htdocs/core/tpl/objectline_view.tpl.php +++ b/htdocs/core/tpl/objectline_view.tpl.php @@ -2,6 +2,8 @@ /* Copyright (C) 2010-2013 Regis Houssin * Copyright (C) 2010-2011 Laurent Destailleur * Copyright (C) 2012-2013 Christophe Battarel + * Copyright (C) 2012 Cédric Salvador + * Copyright (C) 2012-2014 Raphaël Doursenaud * Copyright (C) 2013 Florian Henry * * This program is free software; you can redistribute it and/or modify @@ -138,6 +140,11 @@ if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0;   situation_cycle_ref) { + $coldisplay++; + print '' . $line->situation_percent . '%'; + } + if (! empty($conf->margin->enabled) && empty($user->societe_id)) { $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); ?> @@ -167,12 +174,16 @@ if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0; - id; ?>"> - - + situation_counter == 1 || !$this->situation_cycle_ref) { + print 'id . '">'; + print img_delete(); + print ''; + } + ?> - 1 && empty($conf->browser->phone)) { ?> + 1 && empty($conf->browser->phone) && ($this->situation_counter == 1 || !$this->situation_cycle_ref)) { ?> 0) { ?> id; ?>"> diff --git a/htdocs/cron/card.php b/htdocs/cron/card.php index 4c3ac6b6928..34d201c9144 100644 --- a/htdocs/cron/card.php +++ b/htdocs/cron/card.php @@ -353,16 +353,20 @@ if (($action=="create") || ($action=="edit")) print ""; print $langs->trans('CronEvery').""; print "unitfrequency=="60"){ + if($object->unitfrequency=="60") + { $input .= ' checked="checked" />'; } else{ diff --git a/htdocs/custom/.gitignore b/htdocs/custom/.gitignore new file mode 100644 index 00000000000..89ebd12182c --- /dev/null +++ b/htdocs/custom/.gitignore @@ -0,0 +1,4 @@ +/* +!.gitignore +!README.md +!index.html \ No newline at end of file diff --git a/htdocs/printipp/admin/index.html b/htdocs/custom/index.html similarity index 100% rename from htdocs/printipp/admin/index.html rename to htdocs/custom/index.html diff --git a/htdocs/ecm/class/ecmdirectory.class.php b/htdocs/ecm/class/ecmdirectory.class.php index a4379250914..5edd4c3ce11 100644 --- a/htdocs/ecm/class/ecmdirectory.class.php +++ b/htdocs/ecm/class/ecmdirectory.class.php @@ -414,19 +414,20 @@ class EcmDirectory // extends CommonObject global $langs; $result=''; + //$newref=str_replace('_',' ',$this->ref); + $newref=$this->ref; + $newlabel=$langs->trans("ShowECMSection").': '.$newref; + $linkclose='"'.($more?' '.$more:'').' title="'.dol_escape_htmltag($newlabel, 1).'" class="classfortooltip">'; - $lien = ''; - if ($option == 'index') $lien = ''; - if ($option == 'indexexpanded') $lien = ''; - if ($option == 'indexnotexpanded') $lien = ''; - $lienfin=''; + $lien = 'ref); - $newref=$this->ref; - $newlabel=$langs->trans("ShowECMSection").': '.$newref; if ($withpicto) $result.=($lien.img_object($newlabel, $picto, 'class="classfortooltip"').$lienfin); if ($withpicto && $withpicto != 2) $result.=' '; diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index 7ccd24f871b..c93ec795dec 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -108,477 +108,313 @@ $parameters=array(); $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -if ($action == 'add') +if (empty($reshook)) { - $error=0; - - $db->begin(); - - $object->note = GETPOST('note','alpha'); - $object->origin = $origin; - $object->origin_id = $origin_id; - $object->weight = GETPOST('weight','int')==''?"NULL":GETPOST('weight','int'); - $object->sizeH = GETPOST('sizeH','int')==''?"NULL":GETPOST('sizeH','int'); - $object->sizeW = GETPOST('sizeW','int')==''?"NULL":GETPOST('sizeW','int'); - $object->sizeS = GETPOST('sizeS','int')==''?"NULL":GETPOST('sizeS','int'); - $object->size_units = GETPOST('size_units','int'); - $object->weight_units = GETPOST('weight_units','int'); - - $date_delivery = dol_mktime(GETPOST('date_deliveryhour','int'), GETPOST('date_deliverymin','int'), 0, GETPOST('date_deliverymonth','int'), GETPOST('date_deliveryday','int'), GETPOST('date_deliveryyear','int')); - - // On va boucler sur chaque ligne du document d'origine pour completer objet expedition - // avec info diverses + qte a livrer - $classname = ucfirst($object->origin); - $objectsrc = new $classname($db); - $objectsrc->fetch($object->origin_id); - - $object->socid = $objectsrc->socid; - $object->ref_customer = $objectsrc->ref_client; - $object->date_delivery = $date_delivery; // Date delivery planed - $object->fk_delivery_address = $objectsrc->fk_delivery_address; - $object->shipping_method_id = GETPOST('shipping_method_id','int'); - $object->tracking_number = GETPOST('tracking_number','alpha'); - $object->ref_int = GETPOST('ref_int','alpha'); - $object->note_private = GETPOST('note_private'); - $object->note_public = GETPOST('note_public'); - - $num=count($objectsrc->lines); - $totalqty=0; - for ($i = 0; $i < $num; $i++) - { - $qty = "qtyl".$i; - $j=0; - $sub_qty=array(); - $subtotalqty=0; - $idl="idl".$i; - $batch="batchl".$i."_0"; - if (isset($_POST[$batch])) { - //shipment line with batch-enable product - $qty .= '_'.$j; - while (isset($_POST[$batch])) { - $sub_qty[$j]['q']=GETPOST($qty,'int'); - $sub_qty[$j]['id_batch']=GETPOST($batch,'int'); - $subtotalqty+=$sub_qty[$j]['q']; - $j++; - $batch="batchl".$i."_".$j; - $qty = "qtyl".$i.'_'.$j; - - } - $batch_line[$i]['detail']=$sub_qty; - $batch_line[$i]['qty']=$subtotalqty; - $batch_line[$i]['ix_l']=GETPOST($idl,'int'); - $totalqty+=$subtotalqty; - } else { - //Standard product - if (GETPOST($qty,'int') > 0) $totalqty+=GETPOST($qty,'int'); - } - } - - if ($totalqty > 0) - { - //var_dump($_POST);exit; - for ($i = 0; $i < $num; $i++) - { - $qty = "qtyl".$i; - if (! isset($batch_line[$i])) { - if (GETPOST($qty,'int') > 0 || (GETPOST($qty,'int') == 0 && $conf->global->SHIPMENT_GETS_ALL_ORDER_PRODUCTS)) - { - $ent = "entl".$i; - $idl = "idl".$i; - $entrepot_id = is_numeric(GETPOST($ent,'int'))?GETPOST($ent,'int'):GETPOST('entrepot_id','int'); - if ($entrepot_id < 0) $entrepot_id=''; - - $ret=$object->addline($entrepot_id,GETPOST($idl,'int'),GETPOST($qty,'int')); - if ($ret < 0) - { - $mesg='
'.$object->error.'
'; - $error++; - } - } - } else { - if ($batch_line[$i]['qty']>0) { - $ret=$object->addline_batch($batch_line[$i]); - if ($ret < 0) - { - $mesg='
'.$object->error.'
'; - $error++; - } - } - } - } - - if (! $error) - { - $ret=$object->create($user); - if ($ret <= 0) - { - $mesg='
'.$object->error.'
'; - $error++; - } - } - } - else - { - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Qty")).'
'; - $error++; - } - - if (! $error) - { - $db->commit(); - header("Location: card.php?id=".$object->id); - exit; - } - else - { - $db->rollback(); - $_GET["commande_id"]=GETPOST('commande_id','int'); - $action='create'; - } -} - -/* - * Build a receiving receipt - */ -else if ($action == 'create_delivery' && $conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer) -{ - $result = $object->create_delivery($user); - if ($result > 0) - { - header("Location: ".DOL_URL_ROOT.'/livraison/card.php?id='.$result); - exit; - } - else - { - $mesg=$object->error; - } -} - -else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->expedition->valider) -{ - $object->fetch_thirdparty(); - - $result = $object->valid($user); - - if ($result < 0) - { - $langs->load("errors"); - setEventMessage($langs->trans($object->error),'errors'); - } - else - { - // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; - if (! empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $model=$object->modelpdf; - $ret = $object->fetch($id); // Reload to get new records - - $result=$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - if ($result < 0) dol_print_error($db,$result); - } - } -} - -else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expedition->supprimer) -{ - $result = $object->delete(); - if ($result > 0) - { - header("Location: ".DOL_URL_ROOT.'/expedition/index.php'); - exit; - } - else + if ($action == 'add') { - $langs->load("errors"); - setEventMessage($langs->trans($object->error),'errors'); - } -} + $error=0; -else if ($action == 'reopen' && $user->rights->expedition->valider) -{ - $result = $object->setStatut(0); - if ($result < 0) - { - $mesg = $object->error; - } -} + $db->begin(); -else if ($action == 'setdate_livraison' && $user->rights->expedition->creer) -{ - //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year']; - $datedelivery=dol_mktime(GETPOST('liv_hour','int'), GETPOST('liv_min','int'), 0, GETPOST('liv_month','int'), GETPOST('liv_day','int'), GETPOST('liv_year','int')); + $object->note = GETPOST('note','alpha'); + $object->origin = $origin; + $object->origin_id = $origin_id; + $object->weight = GETPOST('weight','int')==''?"NULL":GETPOST('weight','int'); + $object->sizeH = GETPOST('sizeH','int')==''?"NULL":GETPOST('sizeH','int'); + $object->sizeW = GETPOST('sizeW','int')==''?"NULL":GETPOST('sizeW','int'); + $object->sizeS = GETPOST('sizeS','int')==''?"NULL":GETPOST('sizeS','int'); + $object->size_units = GETPOST('size_units','int'); + $object->weight_units = GETPOST('weight_units','int'); - $object->fetch($id); - $result=$object->set_date_livraison($user,$datedelivery); - if ($result < 0) - { - $mesg='
'.$object->error.'
'; - } -} + $date_delivery = dol_mktime(GETPOST('date_deliveryhour','int'), GETPOST('date_deliverymin','int'), 0, GETPOST('date_deliverymonth','int'), GETPOST('date_deliveryday','int'), GETPOST('date_deliveryyear','int')); -// Action update description of emailing -else if ($action == 'settrackingnumber' || $action == 'settrackingurl' -|| $action == 'settrueWeight' -|| $action == 'settrueWidth' -|| $action == 'settrueHeight' -|| $action == 'settrueDepth' -|| $action == 'setshipping_method_id') -{ - $error=0; + // On va boucler sur chaque ligne du document d'origine pour completer objet expedition + // avec info diverses + qte a livrer + $classname = ucfirst($object->origin); + $objectsrc = new $classname($db); + $objectsrc->fetch($object->origin_id); - if ($action == 'settrackingnumber') $object->tracking_number = trim(GETPOST('trackingnumber','alpha')); - if ($action == 'settrackingurl') $object->tracking_url = trim(GETPOST('trackingurl','int')); - if ($action == 'settrueWeight') { - $object->trueWeight = trim(GETPOST('trueWeight','int')); - $object->weight_units = GETPOST('weight_units','int'); - } - if ($action == 'settrueWidth') $object->trueWidth = trim(GETPOST('trueWidth','int')); - if ($action == 'settrueHeight'){ - $object->trueHeight = trim(GETPOST('trueHeight','int')); - $object->size_units = GETPOST('size_units','int'); + $object->socid = $objectsrc->socid; + $object->ref_customer = $objectsrc->ref_client; + $object->date_delivery = $date_delivery; // Date delivery planed + $object->fk_delivery_address = $objectsrc->fk_delivery_address; + $object->shipping_method_id = GETPOST('shipping_method_id','int'); + $object->tracking_number = GETPOST('tracking_number','alpha'); + $object->ref_int = GETPOST('ref_int','alpha'); + $object->note_private = GETPOST('note_private'); + $object->note_public = GETPOST('note_public'); + + $num=count($objectsrc->lines); + $totalqty=0; + for ($i = 0; $i < $num; $i++) + { + $qty = "qtyl".$i; + $j=0; + $sub_qty=array(); + $subtotalqty=0; + $idl="idl".$i; + $batch="batchl".$i."_0"; + if (isset($_POST[$batch])) { + //shipment line with batch-enable product + $qty .= '_'.$j; + while (isset($_POST[$batch])) { + $sub_qty[$j]['q']=GETPOST($qty,'int'); + $sub_qty[$j]['id_batch']=GETPOST($batch,'int'); + $subtotalqty+=$sub_qty[$j]['q']; + $j++; + $batch="batchl".$i."_".$j; + $qty = "qtyl".$i.'_'.$j; + + } + $batch_line[$i]['detail']=$sub_qty; + $batch_line[$i]['qty']=$subtotalqty; + $batch_line[$i]['ix_l']=GETPOST($idl,'int'); + $totalqty+=$subtotalqty; + } else { + //Standard product + if (GETPOST($qty,'int') > 0) $totalqty+=GETPOST($qty,'int'); + } + } + + if ($totalqty > 0) + { + //var_dump($_POST);exit; + for ($i = 0; $i < $num; $i++) + { + $qty = "qtyl".$i; + if (! isset($batch_line[$i])) { + if (GETPOST($qty,'int') > 0 || (GETPOST($qty,'int') == 0 && $conf->global->SHIPMENT_GETS_ALL_ORDER_PRODUCTS)) + { + $ent = "entl".$i; + $idl = "idl".$i; + $entrepot_id = is_numeric(GETPOST($ent,'int'))?GETPOST($ent,'int'):GETPOST('entrepot_id','int'); + if ($entrepot_id < 0) $entrepot_id=''; + + $ret=$object->addline($entrepot_id,GETPOST($idl,'int'),GETPOST($qty,'int')); + if ($ret < 0) + { + $mesg='
'.$object->error.'
'; + $error++; + } + } + } else { + if ($batch_line[$i]['qty']>0) { + $ret=$object->addline_batch($batch_line[$i]); + if ($ret < 0) + { + $mesg='
'.$object->error.'
'; + $error++; + } + } + } + } + + if (! $error) + { + $ret=$object->create($user); + if ($ret <= 0) + { + $mesg='
'.$object->error.'
'; + $error++; + } + } + } + else + { + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Qty")).'
'; + $error++; + } + + if (! $error) + { + $db->commit(); + header("Location: card.php?id=".$object->id); + exit; + } + else + { + $db->rollback(); + $_GET["commande_id"]=GETPOST('commande_id','int'); + $action='create'; + } } - if ($action == 'settrueDepth') $object->trueDepth = trim(GETPOST('trueDepth','int')); - if ($action == 'setshipping_method_id') $object->shipping_method_id = trim(GETPOST('shipping_method_id','int')); - if (! $error) - { - if ($object->update($user) >= 0) - { - header("Location: card.php?id=".$object->id); - exit; - } - setEventMessage($object->error,'errors'); - } + /* + * Build a receiving receipt + */ + else if ($action == 'create_delivery' && $conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer) + { + $result = $object->create_delivery($user); + if ($result > 0) + { + header("Location: ".DOL_URL_ROOT.'/livraison/card.php?id='.$result); + exit; + } + else + { + $mesg=$object->error; + } + } - $action=""; -} + else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->expedition->valider) + { + $object->fetch_thirdparty(); -// Build document -else if ($action == 'builddoc') // En get ou en post -{ + $result = $object->valid($user); - // Save last template used to generate document - if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); + if ($result < 0) + { + $langs->load("errors"); + setEventMessage($langs->trans($object->error),'errors'); + } + else + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model=$object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id','alpha'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$shipment->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - $result = $object->generateDocument($object->modelpdf, $outputlangs); - if ($result <= 0) - { - dol_print_error($db,$result); - exit; - } -} + $result=$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + if ($result < 0) dol_print_error($db,$result); + } + } + } -// Delete file in doc form -elseif ($action == 'remove_file') -{ - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expedition->supprimer) + { + $result = $object->delete(); + if ($result > 0) + { + header("Location: ".DOL_URL_ROOT.'/expedition/index.php'); + exit; + } + else + { + $langs->load("errors"); + setEventMessage($langs->trans($object->error),'errors'); + } + } - $upload_dir = $conf->expedition->dir_output . "/sending"; - $file = $upload_dir . '/' . GETPOST('file'); - $ret=dol_delete_file($file,0,0,0,$object); - if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile'))); - else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors'); -} + else if ($action == 'reopen' && $user->rights->expedition->valider) + { + $result = $object->setStatut(0); + if ($result < 0) + { + $mesg = $object->error; + } + } -/* - * Add file in email form -*/ -if (GETPOST('addfile','alpha')) -{ - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + else if ($action == 'setdate_livraison' && $user->rights->expedition->creer) + { + //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year']; + $datedelivery=dol_mktime(GETPOST('liv_hour','int'), GETPOST('liv_min','int'), 0, GETPOST('liv_month','int'), GETPOST('liv_day','int'), GETPOST('liv_year','int')); - // Set tmp user directory TODO Use a dedicated directory for temp mails files - $vardir=$conf->user->dir_output."/".$user->id; - $upload_dir_tmp = $vardir.'/temp'; + $object->fetch($id); + $result=$object->set_date_livraison($user,$datedelivery); + if ($result < 0) + { + $mesg='
'.$object->error.'
'; + } + } - dol_add_file_process($upload_dir_tmp,0,0); - $action ='presend'; -} + // Action update description of emailing + else if ($action == 'settrackingnumber' || $action == 'settrackingurl' + || $action == 'settrueWeight' + || $action == 'settrueWidth' + || $action == 'settrueHeight' + || $action == 'settrueDepth' + || $action == 'setshipping_method_id') + { + $error=0; -/* - * Remove file in email form -*/ -if (GETPOST('removedfile','alpha')) -{ - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + if ($action == 'settrackingnumber') $object->tracking_number = trim(GETPOST('trackingnumber','alpha')); + if ($action == 'settrackingurl') $object->tracking_url = trim(GETPOST('trackingurl','int')); + if ($action == 'settrueWeight') { + $object->trueWeight = trim(GETPOST('trueWeight','int')); + $object->weight_units = GETPOST('weight_units','int'); + } + if ($action == 'settrueWidth') $object->trueWidth = trim(GETPOST('trueWidth','int')); + if ($action == 'settrueHeight'){ + $object->trueHeight = trim(GETPOST('trueHeight','int')); + $object->size_units = GETPOST('size_units','int'); + } + if ($action == 'settrueDepth') $object->trueDepth = trim(GETPOST('trueDepth','int')); + if ($action == 'setshipping_method_id') $object->shipping_method_id = trim(GETPOST('shipping_method_id','int')); - // Set tmp user directory - $vardir=$conf->user->dir_output."/".$user->id; - $upload_dir_tmp = $vardir.'/temp'; + if (! $error) + { + if ($object->update($user) >= 0) + { + header("Location: card.php?id=".$object->id); + exit; + } + setEventMessage($object->error,'errors'); + } - // TODO Delete only files that was uploaded from email form - dol_remove_file_process(GETPOST('removedfile','int'),0); - $action ='presend'; -} + $action=""; + } -/* - * Send mail -*/ -if ($action == 'send' && ! GETPOST('addfile','alpha') && ! GETPOST('removedfile','alpha') && ! GETPOST('cancel','alpha')) -{ - $langs->load('mails'); + // Build document + else if ($action == 'builddoc') // En get ou en post + { + // Save last template used to generate document + if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); -// $ref = dol_sanitizeFileName($object->ref); -// $file = $conf->expedition->dir_output . '/sending/' . $ref . '/' . $ref . '.pdf'; + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$shipment->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + $result = $object->generateDocument($object->modelpdf, $outputlangs); + if ($result <= 0) + { + dol_print_error($db,$result); + exit; + } + } -// if (is_readable($file)) -// { - if (GETPOST('sendto','alpha')) - { - // Le destinataire a ete fourni via le champ libre - $sendto = GETPOST('sendto','alpha'); - $sendtoid = 0; - } - elseif (GETPOST('receiver','alpha') != '-1') - { - // Recipient was provided from combo list - if (GETPOST('receiver','alpha') == 'thirdparty') // Id of third party - { - $sendto = $object->client->email; - $sendtoid = 0; - } - else // Id du contact - { - $sendto = $object->client->contact_get_property(GETPOST('receiver','alpha'),'email'); - $sendtoid = GETPOST('receiver','alpha'); - } - } + // Delete file in doc form + elseif ($action == 'remove_file') + { + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - if (dol_strlen($sendto)) - { - $langs->load("commercial"); + $upload_dir = $conf->expedition->dir_output . "/sending"; + $file = $upload_dir . '/' . GETPOST('file'); + $ret=dol_delete_file($file,0,0,0,$object); + if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile'))); + else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors'); + } - $from = GETPOST('fromname','alpha') . ' <' . GETPOST('frommail','alpha') .'>'; - $replyto = GETPOST('replytoname','alpha'). ' <' . GETPOST('replytomail','alpha').'>'; - $message = GETPOST('message'); - $sendtocc = GETPOST('sendtocc','alpha'); - $deliveryreceipt = GETPOST('deliveryreceipt','alpha'); + elseif ($action == 'classifybilled') + { + $object->fetch($id); + $object->set_billed(); + } - if ($action == 'send') - { - if (dol_strlen(GETPOST('subject','alpha'))) $subject=GETPOST('subject','alpha'); - else $subject = $langs->transnoentities('Shipping').' '.$object->ref; - $actiontypecode='AC_SHIP'; - $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto; - if ($message) - { - if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc); - $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject); - $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":"); - $actionmsg = dol_concatdesc($actionmsg, $message); - } - $actionmsg2=$langs->transnoentities('Action'.$actiontypecode); - } + include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; - // Create form object - include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; - $formmail = new FormMail($db); + // Actions to send emails + if (empty($id)) $id=$facid; + $actiontypecode='AC_SHIP'; + $trigger_name='SHIPPING_SENTBYMAIL'; + $paramname='id'; + $mode='emailfromshipment'; + include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; - $attachedfiles=$formmail->get_attached_files(); - $filepath = $attachedfiles['paths']; - $filename = $attachedfiles['names']; - $mimetype = $attachedfiles['mimes']; - - // Send mail - require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; - $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt,-1); - if ($mailfile->error) - { - $mesg='
'.$mailfile->error.'
'; - } - else - { - $result=$mailfile->sendfile(); - if ($result) - { - $error=0; - - // Initialisation donnees - $object->sendtoid = $sendtoid; - $object->actiontypecode = $actiontypecode; - $object->actionmsg = $actionmsg; - $object->actionmsg2 = $actionmsg2; - $object->fk_element = $object->id; - $object->elementtype = $object->element; - - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($db); - $result=$interface->run_triggers('SHIPPING_SENTBYMAIL',$object,$user,$langs,$conf); - if ($result < 0) { - $error++; $object->errors=$interface->errors; - } - // Fin appel triggers - - if ($error) - { - dol_print_error($db); - } - else - { - // Redirect here - // This avoid sending mail twice if going out and then back to page - $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); - setEventMessage($mesg); - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } - } - else - { - $langs->load("other"); - $mesg='
'; - if ($mailfile->error) - { - $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto); - $mesg.='
'.$mailfile->error; - } - else - { - $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; - } - $mesg.='
'; - } - } - } - else - { - $langs->load("other"); - $mesg='
'.$langs->trans('ErrorMailRecipientIsEmpty').' !
'; - $action='presend'; - dol_syslog('Recipient email is empty'); - } -/* } - else - { - $langs->load("errors"); - $mesg='
'.$langs->trans('ErrorCantReadFile',$file).'
'; - dol_syslog('Failed to read file: '.$file); - }*/ -} - -else if ($action == 'classifybilled') -{ - $object->fetch($id); - $object->set_billed(); } diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 46f2cbc70fe..00105cf967a 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -121,21 +121,30 @@ class Expedition extends CommonObject global $db, $langs, $conf; $langs->load("sendings"); - $dir = DOL_DOCUMENT_ROOT . "/core/modules/expedition"; - - if (empty($conf->global->EXPEDITION_ADDON_NUMBER)) + if (!empty($conf->global->EXPEDITION_ADDON_NUMBER)) { - $conf->global->EXPEDITION_ADDON_NUMBER='mod_expedition_safor'; - } + $mybool = false; - $file = $conf->global->EXPEDITION_ADDON_NUMBER.".php"; + $file = $conf->global->EXPEDITION_ADDON_NUMBER.".php"; + $classname = $conf->global->EXPEDITION_ADDON_NUMBER; - // Chargement de la classe de numerotation - $classname = $conf->global->EXPEDITION_ADDON_NUMBER; + // Include file with class + $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); + + foreach ($dirmodels as $reldir) { + + $dir = dol_buildpath($reldir."core/modules/expedition/"); + + // Load file with numbering class (if found) + $mybool|=@include_once $dir.$file; + } + + if (! $mybool) + { + dol_print_error('',"Failed to include file ".$file); + return ''; + } - $result=include_once $dir.'/'.$file; - if ($result) - { $obj = new $classname(); $numref = ""; $numref = $obj->getNextValue($soc,$this); @@ -149,12 +158,12 @@ class Expedition extends CommonObject dol_print_error($db,get_class($this)."::getNextNumRef ".$obj->error); return ""; } - } - else - { - print $langs->trans("Error")." ".$langs->trans("Error_EXPEDITION_ADDON_NUMBER_NotDefined"); - return ""; - } + } + else + { + print $langs->trans("Error")." ".$langs->trans("Error_EXPEDITION_ADDON_NUMBER_NotDefined"); + return ""; + } } /** @@ -1208,16 +1217,16 @@ class Expedition extends CommonObject global $langs; $result=''; + $label=$langs->trans("ShowSending").': '.$this->ref; $url = DOL_URL_ROOT.'/expedition/card.php?id='.$this->id; if ($short) return $url; - $linkstart = '
'; + $linkstart = ''; $linkend=''; $picto='sending'; - $label=$langs->trans("ShowSending").': '.$this->ref; if ($withpicto) $result.=($linkstart.img_object($label, $picto, 'class="classfortooltip"').$linkend); if ($withpicto && $withpicto != 2) $result.=' '; diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index b7887c25278..58c0efdda9a 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -547,13 +547,13 @@ class Fichinter extends CommonObject global $langs; $result=''; + $label=$langs->trans("Show").': '.$this->ref; - $lien = ''; + $lien = ''; $lienfin=''; $picto='intervention'; - $label=$langs->trans("Show").': '.$this->ref; if ($withpicto) $result.=($lien.img_object($label, $picto, 'class="classfortooltip"').$lienfin); if ($withpicto && $withpicto != 2) $result.=' '; @@ -574,25 +574,33 @@ class Fichinter extends CommonObject global $conf, $db, $langs; $langs->load("interventions"); - $dir = DOL_DOCUMENT_ROOT . "/core/modules/fichinter/"; - if (! empty($conf->global->FICHEINTER_ADDON)) { - $file = $conf->global->FICHEINTER_ADDON.".php"; - $classname = $conf->global->FICHEINTER_ADDON; - if (! file_exists($dir.$file)) - { - $file='mod_'.$file; - $classname='mod_'.$classname; + $mybool = false; + + $file = "mod_".$conf->global->FICHEINTER_ADDON.".php"; + $classname = "mod_".$conf->global->FICHEINTER_ADDON; + + // Include file with class + $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); + + foreach ($dirmodels as $reldir) { + + $dir = dol_buildpath($reldir."core/modules/fichinter/"); + + // Load file with numbering class (if found) + $mybool|=@include_once $dir.$file; } - // Chargement de la classe de numerotation - require_once $dir.$file; + if (! $mybool) + { + dol_print_error('',"Failed to include file ".$file); + return ''; + } $obj = new $classname(); - $numref = ""; - $numref = $obj->getNumRef($soc,$this); + $numref = $obj->getNextValue($soc,$this); if ( $numref != "") { @@ -606,6 +614,7 @@ class Fichinter extends CommonObject } else { + $langs->load("errors"); print $langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined"); return ""; } diff --git a/htdocs/fourn/ajax/getSupplierPrices.php b/htdocs/fourn/ajax/getSupplierPrices.php index 907e34f8d35..e14e872a24f 100755 --- a/htdocs/fourn/ajax/getSupplierPrices.php +++ b/htdocs/fourn/ajax/getSupplierPrices.php @@ -28,6 +28,7 @@ if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; $idprod=GETPOST('idprod','int'); @@ -43,8 +44,11 @@ top_httphead(); //print ''."\n"; -if (! empty($idprod)) +if ($idprod > 0) { + $producttmp=new ProductFournisseur($db); + $producttmp->fetch($idprod); + $sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration,"; $sql.= " pfp.ref_fourn,"; $sql.= " pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice, pfp.charges, pfp.unitcharges,"; @@ -111,6 +115,7 @@ if (! empty($idprod)) if ($objp->duration) $label .= " - ".$objp->duration; $label = price($price,0,$langs,0,0,-1,$conf->currency)."/".$langs->trans("Unit"); + if ($objp->ref_fourn) $label.=' ('.$objp->ref_fourn.')'; $prices[] = array("id" => $objp->idprodfournprice, "price" => price($price,0,'',0), "label" => $label, "title" => $title); $i++; @@ -121,9 +126,8 @@ if (! empty($idprod)) } // Add price for pmp - $price=123; + $price=$producttmp->pmp; $prices[] = array("id" => 'pmpprice', "price" => $price, "label" => $langs->trans("PMPValueShort").': '.price($price,0,$langs,0,0,-1,$conf->currency), "title" => $langs->trans("PMPValueShort").': '.price($price,0,$langs,0,0,-1,$conf->currency)); - } echo json_encode($prices); diff --git a/htdocs/fourn/card.php b/htdocs/fourn/card.php index 8511a3e1a48..0fefa8d4555 100644 --- a/htdocs/fourn/card.php +++ b/htdocs/fourn/card.php @@ -41,6 +41,7 @@ $langs->load('companies'); $langs->load('commercial'); $action = GETPOST('action'); +$cancelbutton = GETPOST('cancel'); // Security check $id = (GETPOST('socid','int') ? GETPOST('socid','int') : GETPOST('id','int')); @@ -60,10 +61,14 @@ $parameters=array('socid'=>$socid); $reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -if ($action == 'setsupplieraccountancycode') +if (empty($reshook)) { - $cancelbutton = GETPOST('cancel'); - if (! $cancelbutton) + if ($cancelbutton) + { + $action = ""; + } + + if ($action == 'setsupplieraccountancycode') { $result=$object->fetch($id); $object->code_compta_fournisseur=$_POST["supplieraccountancycode"]; @@ -73,21 +78,20 @@ if ($action == 'setsupplieraccountancycode') $mesg=join(',',$object->errors); } } - $action=""; -} -// conditions de reglement -if ($action == 'setconditions' && $user->rights->societe->creer) -{ - $object->fetch($id); - $result=$object->setPaymentTerms(GETPOST('cond_reglement_supplier_id','int')); - if ($result < 0) dol_print_error($db,$object->error); -} -// mode de reglement -if ($action == 'setmode' && $user->rights->societe->creer) -{ - $object->fetch($id); - $result=$object->setPaymentMethods(GETPOST('mode_reglement_supplier_id','int')); - if ($result < 0) dol_print_error($db,$object->error); + // conditions de reglement + if ($action == 'setconditions' && $user->rights->societe->creer) + { + $object->fetch($id); + $result=$object->setPaymentTerms(GETPOST('cond_reglement_supplier_id','int')); + if ($result < 0) dol_print_error($db,$object->error); + } + // mode de reglement + if ($action == 'setmode' && $user->rights->societe->creer) + { + $object->fetch($id); + $result=$object->setPaymentMethods(GETPOST('mode_reglement_supplier_id','int')); + if ($result < 0) dol_print_error($db,$object->error); + } } @@ -98,12 +102,22 @@ if ($action == 'setmode' && $user->rights->societe->creer) $contactstatic = new Contact($db); $form = new Form($db); -if ($object->fetch($id)) +if ($id > 0 && empty($object->id)) { - llxHeader('',$langs->trans('SupplierCard')); + // Load data of third party + $res=$object->fetch($id); + if ($object->id <= 0) dol_print_error($db,$object->error); +} + +if ($object->id > 0) +{ + $title=$langs->trans("SupplierCard"); + if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name; + $help_url=''; + llxHeader('',$title, $help_url); /* - * Affichage onglets + * Show tabs */ $head = societe_prepare_head($object); @@ -285,7 +299,7 @@ if ($object->fetch($id)) print ''; print ''; print '
'.$langs->trans("ProductsAndServices").''; - print ''.$langs->trans("All").' ('.$object->nbOfProductRefs().')'; + print ''.$langs->trans("All").' '.$object->nbOfProductRefs().''; print '
'; } @@ -341,7 +355,7 @@ if ($object->fetch($id)) print ''; print ''; print ''; - print ''; + print ''; print ''; print '
'.$langs->trans("LastOrders",($num<$MAXLIST?"":$MAXLIST)).''.$langs->trans("AllOrders").' ('.$num.')'.$langs->trans("AllOrders").' '.$num.''.img_picto($langs->trans("Statistics"),'stats').'
'; print ''; @@ -353,7 +367,11 @@ if ($object->fetch($id)) $var=!$var; print ""; - print ''.img_object($langs->trans("ShowOrder"),"order")." ".$obj->ref.''; + print ''; + $orderstatic->id=$obj->rowid; + $orderstatic->ref=$obj->ref; + print $orderstatic->getNomUrl(1); + print ''; print ''; if ($obj->dc) { @@ -408,7 +426,7 @@ if ($object->fetch($id)) print ''; print ''; - print ''; + print '
'.$langs->trans('LastSuppliersBills',($num<=$MAXLIST?"":$MAXLIST)).''.$langs->trans('AllBills').' ('.$num.')
'; print ''; print '
'.$langs->trans('LastSuppliersBills',($num<=$MAXLIST?"":$MAXLIST)).''.$langs->trans('AllBills').' '.$num.''.img_picto($langs->trans("Statistics"),'stats').'
'; print ''; diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 3ac895f2764..ef25be9469f 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -531,12 +531,12 @@ class CommandeFournisseur extends CommonOrder global $langs; $result=''; + $label=$langs->trans("ShowOrder").': '.$this->ref; - $lien = ''; + $lien = ''; $lienfin=''; $picto='order'; - $label=$langs->trans("ShowOrder").': '.$this->ref; if ($withpicto) $result.=($lien.img_object($label, $picto, 'class="classfortooltip"').$lienfin); if ($withpicto && $withpicto != 2) $result.=' '; @@ -557,44 +557,48 @@ class CommandeFournisseur extends CommonOrder global $db, $langs, $conf; $langs->load("orders"); - $dir = DOL_DOCUMENT_ROOT .'/core/modules/supplier_order/'; - if (! empty($conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER)) { + $mybool = false; + $file = $conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER.'.php'; + $classname=$conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER; - if (is_readable($dir.'/'.$file)) + // Include file with class + $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); + + foreach ($dirmodels as $reldir) { + + $dir = dol_buildpath($reldir."core/modules/supplier_order/"); + + // Load file with numbering class (if found) + $mybool|=@include_once $dir.$file; + } + + if (! $mybool) { - // Definition du nom de modele de numerotation de commande fournisseur - $modName=$conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER; - require_once $dir.'/'.$file; + dol_print_error('',"Failed to include file ".$file); + return ''; + } - // Recuperation de la nouvelle reference - $objMod = new $modName($this->db); + $obj = new $classname(); + $numref = $obj->getNextValue($soc,$this); - $numref = ""; - $numref = $objMod->commande_get_num($soc,$this); - - if ( $numref != "") - { - return $numref; - } - else - { - dol_print_error($db, get_class($this)."::getNextNumRef ".$obj->error); - return -1; - } + if ( $numref != "") + { + return $numref; } else - { - print $langs->trans("Error")." ".$langs->trans("Error_FailedToLoad_COMMANDE_SUPPLIER_ADDON_File",$conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER); - return -2; + { + $this->error = $obj->error; + dol_print_error($db, get_class($this)."::getNextNumRef ".$obj->error); + return -1; } } else - { - print $langs->trans("Error")." ".$langs->trans("Error_COMMANDE_SUPPLIER_ADDON_NotDefined"); - return -3; + { + $this->error = "Error_COMMANDE_SUPPLIER_ADDON_NotDefined"; + return -2; } } @@ -1074,25 +1078,25 @@ class CommandeFournisseur extends CommonOrder * Add order line * * @param string $desc Description - * @param double $pu_ht Unit price - * @param double $qty Quantity - * @param double $txtva Taux tva - * @param double $txlocaltax1 Localtax1 tax - * @param double $txlocaltax2 Localtax2 tax + * @param float $pu_ht Unit price + * @param float $qty Quantity + * @param float $txtva Taux tva + * @param float $txlocaltax1 Localtax1 tax + * @param float $txlocaltax2 Localtax2 tax * @param int $fk_product Id produit * @param int $fk_prod_fourn_price Id supplier price * @param string $fourn_ref Supplier reference - * @param double $remise_percent Remise + * @param float $remise_percent Remise * @param string $price_base_type HT or TTC - * @param double $pu_ttc Unit price TTC + * @param float $pu_ttc Unit price TTC * @param int $type Type of line (0=product, 1=service) * @param int $info_bits More information - * @param int $notrigger Disable triggers - * @param timestamp $date_start Date start of service - * @param timestamp $date_end Date end of service + * @param bool $notrigger Disable triggers + * @param int $date_start Date start of service + * @param int $date_end Date end of service * @return int <=0 if KO, >0 if OK */ - function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $fk_prod_fourn_price=0, $fourn_ref='', $remise_percent=0, $price_base_type='HT', $pu_ttc=0, $type=0, $info_bits=0, $notrigger=false, $date_start='', $date_end='') + function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $fk_product=0, $fk_prod_fourn_price=0, $fourn_ref='', $remise_percent=0.0, $price_base_type='HT', $pu_ttc=0.0, $type=0, $info_bits=0, $notrigger=false, $date_start=null, $date_end=null) { global $langs,$mysoc; diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index b931b566a61..842fe9fcf0b 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -1472,19 +1472,19 @@ class FactureFournisseur extends CommonInvoice global $langs; $result=''; + $label=$langs->trans("ShowInvoice").': '.$this->ref; + if ($this->ref_supplier) $label.=' / '.$this->ref_supplier; if ($option == 'document') { - $lien = ''; + $lien = ''; $lienfin=''; } else { - $lien = ''; + $lien = ''; $lienfin=''; } - $label=$langs->trans("ShowInvoice").': '.$this->ref; - if ($this->ref_supplier) $label.=' / '.$this->ref_supplier; $ref=$this->ref; if (empty($ref)) $ref=$this->id; @@ -1514,10 +1514,14 @@ class FactureFournisseur extends CommonInvoice $file = $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER.".php"; $classname = $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER; + // Include file with class - foreach ($conf->file->dol_document_root as $dirroot) - { - $dir = $dirroot."/core/modules/supplier_invoice/"; + $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); + + foreach ($dirmodels as $reldir) { + + $dir = dol_buildpath($reldir."core/modules/supplier_invoice/"); + // Load file with numbering class (if found) $mybool|=@include_once $dir.$file; } diff --git a/htdocs/fourn/class/paiementfourn.class.php b/htdocs/fourn/class/paiementfourn.class.php index 443216d899d..3cd3ec0496c 100644 --- a/htdocs/fourn/class/paiementfourn.class.php +++ b/htdocs/fourn/class/paiementfourn.class.php @@ -487,17 +487,17 @@ class PaiementFourn extends Paiement global $langs; $result=''; + $text=$this->ref; // Sometimes ref contains label + if (preg_match('/^\((.*)\)$/i',$text,$reg)) { + // Label generique car entre parentheses. On l'affiche en le traduisant + if ($reg[1]=='paiement') $reg[1]='Payment'; + $text=$langs->trans($reg[1]); + } + $label = $langs->trans("ShowPayment").': '.$text; - $lien = ''; - $lienfin=''; + $lien = ''; + $lienfin=''; - $text=$this->ref; // Sometimes ref contains label - if (preg_match('/^\((.*)\)$/i',$text,$reg)) - { - // Label g诩rique car entre parenth粥s. On l'affiche en le traduisant - if ($reg[1]=='paiement') $reg[1]='Payment'; - $text=$langs->trans($reg[1]); - } if ($withpicto) $result.=($lien.img_object($langs->trans("ShowPayment"), 'payment', 'class="classfortooltip"').$lienfin); if ($withpicto && $withpicto != 2) $result.=' '; diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index b90bd275e4c..57696363289 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -479,14 +479,16 @@ else if ($action == 'confirm_deleteproductline' && $confirm == 'yes' && $user->r $result = $object->deleteline(GETPOST('lineid')); if ($result >= 0) { - $outputlangs = $langs; - if (GETPOST('lang_id')) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang(GETPOST('lang_id')); - } if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } $ret=$object->fetch($object->id); // Reload to get new records $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); } @@ -571,6 +573,14 @@ else if ($action == 'confirm_approve' && $confirm == 'yes' && $user->rights->fou if ($result > 0) { if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); } header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id); diff --git a/htdocs/fourn/facture/paiement.php b/htdocs/fourn/facture/paiement.php index afd914546a6..0864a0bc2a5 100644 --- a/htdocs/fourn/facture/paiement.php +++ b/htdocs/fourn/facture/paiement.php @@ -66,169 +66,172 @@ if ($user->societe_id > 0) // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('paymentsupplier')); -$parameters=array('socid'=>$socid); -$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); /* * Actions */ -if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='yes')) +$parameters=array('socid'=>$socid); +$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + +if (empty($reshook)) { - $error = 0; + if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='yes')) + { + $error = 0; - $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); - $paiement_id = 0; - $totalpayment = 0; - $atleastonepaymentnotnull = 0; + $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); + $paiement_id = 0; + $totalpayment = 0; + $atleastonepaymentnotnull = 0; - // Generate payment array and check if there is payment higher than invoice and payment date before invoice date - $tmpinvoice=new FactureFournisseur($db); - foreach ($_POST as $key => $value) - { - if (substr($key,0,7) == 'amount_') - { - $cursorfacid = substr($key,7); - $amounts[$cursorfacid] = price2num(trim(GETPOST($key))); - $totalpayment = $totalpayment + $amounts[$cursorfacid]; - if (! empty($amounts[$cursorfacid])) $atleastonepaymentnotnull++; - $result=$tmpinvoice->fetch($cursorfacid); - if ($result <= 0) dol_print_error($db); - $amountsresttopay[$cursorfacid]=price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement()); - if ($amounts[$cursorfacid]) - { - // Check amount - if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid]))) + // Generate payment array and check if there is payment higher than invoice and payment date before invoice date + $tmpinvoice=new FactureFournisseur($db); + foreach ($_POST as $key => $value) + { + if (substr($key,0,7) == 'amount_') + { + $cursorfacid = substr($key,7); + $amounts[$cursorfacid] = price2num(trim(GETPOST($key))); + $totalpayment = $totalpayment + $amounts[$cursorfacid]; + if (! empty($amounts[$cursorfacid])) $atleastonepaymentnotnull++; + $result=$tmpinvoice->fetch($cursorfacid); + if ($result <= 0) dol_print_error($db); + $amountsresttopay[$cursorfacid]=price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement()); + if ($amounts[$cursorfacid]) { - $addwarning=1; - $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPaySupplier")).' '.$langs->trans("HelpPaymentHigherThanReminderToPaySupplier"); + // Check amount + if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid]))) + { + $addwarning=1; + $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPaySupplier")).' '.$langs->trans("HelpPaymentHigherThanReminderToPaySupplier"); + } + // Check date + if ($datepaye && ($datepaye < $tmpinvoice->date)) + { + $langs->load("errors"); + //$error++; + setEventMessage($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye,'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), 'warnings'); + } } - // Check date - if ($datepaye && ($datepaye < $tmpinvoice->date)) + + $formquestion[$i++]=array('type' => 'hidden','name' => $key, 'value' => $_POST[$key]); + } + } + + // Check parameters + if ($_POST['paiementid'] <= 0) + { + setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('PaymentMode')), 'errors'); + $error++; + } + + if (! empty($conf->banque->enabled)) + { + // If bank module is on, account is required to enter a payment + if (GETPOST('accountid') <= 0) + { + setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), 'errors'); + $error++; + } + } + + if (empty($totalpayment) && empty($atleastonepaymentnotnull)) + { + setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->trans('PaymentAmount')), 'errors'); + $error++; + } + + if (empty($datepaye)) + { + setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('Date')), 'errors'); + $error++; + } + } + + /* + * Action add_paiement + */ + if ($action == 'add_paiement') + { + if ($error) + { + $action = 'create'; + } + // Le reste propre a cette action s'affiche en bas de page. + } + + + /* + * Action confirm_paiement + */ + if ($action == 'confirm_paiement' && $confirm == 'yes') + { + $error=0; + + $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); + + if (! $error) + { + $db->begin(); + + // Creation de la ligne paiement + $paiement = new PaiementFourn($db); + $paiement->datepaye = $datepaye; + $paiement->amounts = $amounts; // Array of amounts + $paiement->paiementid = $_POST['paiementid']; + $paiement->num_paiement = $_POST['num_paiement']; + $paiement->note = $_POST['comment']; + if (! $error) + { + $paiement_id = $paiement->create($user,(GETPOST('closepaidinvoices')=='on'?1:0)); + if ($paiement_id < 0) { - $langs->load("errors"); - //$error++; - setEventMessage($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye,'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), 'warnings'); + setEventMessage($paiement->error, 'errors'); + $error++; } - } + } - $formquestion[$i++]=array('type' => 'hidden','name' => $key, 'value' => $_POST[$key]); - } - } + if (! $error) + { + $result=$paiement->addPaymentToBank($user,'payment_supplier','(SupplierInvoicePayment)',$_POST['accountid'],'',''); + if ($result < 0) + { + setEventMessage($paiement->error, 'errors'); + $error++; + } + } - // Check parameters - if ($_POST['paiementid'] <= 0) - { - setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('PaymentMode')), 'errors'); - $error++; - } + if (! $error) + { + $db->commit(); - if (! empty($conf->banque->enabled)) - { - // If bank module is on, account is required to enter a payment - if (GETPOST('accountid') <= 0) - { - setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), 'errors'); - $error++; - } - } - - if (empty($totalpayment) && empty($atleastonepaymentnotnull)) - { - setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->trans('PaymentAmount')), 'errors'); - $error++; - } - - if (empty($datepaye)) - { - setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('Date')), 'errors'); - $error++; - } + // If payment dispatching on more than one invoice, we keep on summary page, otherwise go on invoice card + $invoiceid=0; + foreach ($paiement->amounts as $key => $amount) + { + $facid = $key; + if (is_numeric($amount) && $amount <> 0) + { + if ($invoiceid != 0) $invoiceid=-1; // There is more than one invoice payed by this payment + else $invoiceid=$facid; + } + } + if ($invoiceid > 0) $loc = DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$invoiceid; + else $loc = DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$paiement_id; + header('Location: '.$loc); + exit; + } + else + { + $db->rollback(); + } + } + } } -/* - * Action add_paiement - */ -if ($action == 'add_paiement') -{ - if ($error) - { - $action = 'create'; - } - // Le reste propre a cette action s'affiche en bas de page. -} - - -/* - * Action confirm_paiement - */ -if ($action == 'confirm_paiement' && $confirm == 'yes') -{ - $error=0; - - $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); - - if (! $error) - { - $db->begin(); - - // Creation de la ligne paiement - $paiement = new PaiementFourn($db); - $paiement->datepaye = $datepaye; - $paiement->amounts = $amounts; // Array of amounts - $paiement->paiementid = $_POST['paiementid']; - $paiement->num_paiement = $_POST['num_paiement']; - $paiement->note = $_POST['comment']; - if (! $error) - { - $paiement_id = $paiement->create($user,(GETPOST('closepaidinvoices')=='on'?1:0)); - if ($paiement_id < 0) - { - setEventMessage($paiement->error, 'errors'); - $error++; - } - } - - if (! $error) - { - $result=$paiement->addPaymentToBank($user,'payment_supplier','(SupplierInvoicePayment)',$_POST['accountid'],'',''); - if ($result < 0) - { - setEventMessage($paiement->error, 'errors'); - $error++; - } - } - - if (! $error) - { - $db->commit(); - - // If payment dispatching on more than one invoice, we keep on summary page, otherwise go on invoice card - $invoiceid=0; - foreach ($paiement->amounts as $key => $amount) - { - $facid = $key; - if (is_numeric($amount) && $amount <> 0) - { - if ($invoiceid != 0) $invoiceid=-1; // There is more than one invoice payed by this payment - else $invoiceid=$facid; - } - } - if ($invoiceid > 0) $loc = DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$invoiceid; - else $loc = DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$paiement_id; - header('Location: '.$loc); - exit; - } - else - { - $db->rollback(); - } - } -} - - /* * View @@ -458,7 +461,7 @@ if (empty($action)) $search_paymenttype=GETPOST('search_paymenttype'); $search_amount=GETPOST('search_amount'); $search_company=GETPOST('search_company'); - + if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers { $search_ref=""; @@ -596,7 +599,7 @@ if (empty($action)) print ''; print $invoicesupplierstatic->getNomUrl(1); print '';*/ - + print ' '; print ''; $i++; diff --git a/htdocs/fourn/index.php b/htdocs/fourn/index.php index 9da28281779..29f12fed38f 100644 --- a/htdocs/fourn/index.php +++ b/htdocs/fourn/index.php @@ -126,7 +126,7 @@ if (! empty($conf->fournisseur->enabled)) { print ''; print ''; - print ''; + print ''; $i = 0; $var = true; @@ -183,7 +183,7 @@ if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture- { print '
'.$langs->trans("DraftOrders").' ('.$num.')
'.$langs->trans("DraftOrders").' '.$num.'
'; print ''; - print ''; + print ''; $i = 0; $tot_ttc = 0; $var = True; diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php index 1a3e9f7ecd3..280efd4addc 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -658,14 +658,13 @@ class Holiday extends CommonObject global $langs; $result=''; + $label=$langs->trans("Show").': '.$this->ref; - $lien = ''; + $lien = ''; $lienfin=''; $picto='holiday'; - $label=$langs->trans("Show").': '.$this->ref; - if ($withpicto) $result.=($lien.img_object($label, $picto, 'class="classfortooltip"').$lienfin); if ($withpicto && $withpicto != 2) $result.=' '; if ($withpicto != 2) $result.=$lien.$this->ref.$lienfin; diff --git a/htdocs/includes/printipp/BasicIPP.php b/htdocs/includes/printipp/BasicIPP.php index 3869c75bc06..1cc7851fab2 100644 --- a/htdocs/includes/printipp/BasicIPP.php +++ b/htdocs/includes/printipp/BasicIPP.php @@ -1,6 +1,6 @@ errno = $errno; - } - public function getErrorFormatted() - { - $return = sprintf("[ipp]: %s -- " . _(" file %s, line %s"), - $this->getMessage() , $this->getFile() , $this->getLine()); - return $return; - } - public function getErrno() - { - return $this->errno; - } + protected $errno; + + public function __construct($msg, $errno = null) + { + parent::__construct($msg); + $this->errno = $errno; + } + + public function getErrorFormatted() + { + $return = sprintf("[ipp]: %s -- " . _(" file %s, line %s"), + $this->getMessage() , $this->getFile() , $this->getLine()); + return $return; + } + + public function getErrno() + { + return $this->errno; + } } class BasicIPP { - // - // variables declaration - // - - // setup variables - - public $paths = array( - "root" => "/", - "admin" => "/admin/", - "printers" => "/printers/", - "jobs" => "/jobs/" - ); - public $http_timeout = 30; // timeout at http connection (seconds) 0 => default => 30. - public $http_data_timeout = 30; // data reading timeout (milliseconds) 0 => default => 30. - public $ssl = false; - public $debug_level = 3; // max 3: almost silent - public $alert_on_end_tag; // debugging purpose: echo "END tag OK" if (1 and reads while end tag) - public $with_exceptions = 0; // compatibility mode for old scripts - public $handle_http_exceptions = 1; - - // readables variables - - public $jobs = array(); - public $jobs_uri = array(); - public $status = array(); - public $response_completed = array(); - public $last_job = ""; - public $attributes; // object you can read: attributes after validateJob() - public $printer_attributes; // object you can read: printer's attributes after getPrinterAttributes() - public $job_attributes; // object you can read: last job attributes - public $jobs_attributes; // object you can read: jobs attributes after getJobs() - public $available_printers = array(); - public $printers_uri = array(); - public $debug = array(); - public $response; - - // protected variables; - protected $log_level = 2; // max 3: very verbose - protected $log_type = 3; // 3: file | 1: e-mail | 0: logger - protected $log_destination; // e-mail or file - protected $serveroutput; - protected $setup; - protected $stringjob; - protected $data; - protected $debug_count = 0; - protected $username; - protected $charset; - protected $password; - protected $requesring_user; - protected $client_hostname = "localhost"; - protected $stream; - protected $host = "localhost"; - protected $port = "631"; - protected $printer_uri; - protected $timeout = "20"; //20 secs - protected $errNo; - protected $errStr; - protected $datatype; - protected $datahead; - protected $datatail; - public $meta; - protected $operation_id; - protected $delay; - protected $error_generation; //devel feature - protected $debug_http = 0; - protected $no_disconnect; - protected $job_tags; - protected $operation_tags; - protected $index; - protected $collection; //RFC3382 - protected $collection_index; //RFC3382 - protected $collection_key = array(); //RFC3382 - protected $collection_depth = - 1; //RFC3382 - protected $end_collection = false; //RFC3382 - protected $collection_nbr = array(); //RFC3382 - protected $unix = false; // true -> use unix sockets instead of http - - // constructor - public function __construct() - { - $tz = getenv("date.timezone"); - if (!$tz) $tz = @date_default_timezone_get(); - date_default_timezone_set($tz); - $this->meta = new stdClass(); - $this->setup = new stdClass(); - $this->values = new stdClass(); - $this->serveroutput = new stdClass(); - $this->error_generation = new stdClass(); - $this->_parsing = new stdClass(); - self::_initTags(); - } - - /***************** - * - * PUBLIC FUNCTIONS - * - *******************/ - - // - // SETUP - // - - public function setPort($port = '631') - { - $this->port = $port; - self::_putDebug("Port is " . $this->port, 2); - } - - public function setUnix($socket = '/var/run/cups/cups.sock') - { - $this->host = $socket; - $this->unix = true; - self::_putDebug("Host is " . $this->host, 2); - } - - public function setHost($host = 'localhost') - { - $this->host = $host; - $this->unix = false; - self::_putDebug("Host is " . $this->host, 2); - } - - public function setTimeout($timeout) - { - $this->timeout = $timeout; - } - - public function setPrinterURI($uri) - { - $length = strlen($uri); - $length = chr($length); - while (strlen($length) < 2) $length = chr(0x00) . $length; - $this->meta->printer_uri = chr(0x45) // uri type | value-tag - . chr(0x00) . chr(0x0B) // name-length - . "printer-uri" // printer-uri | name - . $length . $uri; - $this->printer_uri = $uri; - self::_putDebug(sprintf(_("Printer URI: %s") , $uri) , 2); - $this->setup->uri = 1; - } - - public function setData($data) - { - $this->data = $data; - self::_putDebug("Data set", 2); - } - - public function setRawText() - { - $this->setup->datatype = 'TEXT'; - $this->meta->mime_media_type = ""; - $this->setup->mime_media_type = 1; - $this->datahead = chr(0x16); - if (is_readable($this->data)) - { - //It's a filename. Open and stream. - $data = fopen($this->data, "rb"); - while (!feof($data)) $output = fread($data, 8192); - } - else - { - $output = $this->data; - } - if (substr($output, -1, 1) != chr(0x0c)) if (!isset($this->setup->noFormFeed)) $this->datatail = chr(0x0c); - self::_putDebug(_("Forcing data to be interpreted as RAW TEXT") , 2); - } - - public function unsetRawText() - { - $this->setup->datatype = 'BINARY'; - $this->datahead = ''; - $this->datatail = ''; - self::_putDebug(_("Unset forcing data to be interpreted as RAW TEXT") , 2); - } - - public function setBinary() - { - self::unsetRawText(); - } - - public function setFormFeed() - { - $this->datatail = "\r\n" . chr(0x0c); - unset($this->setup->noFormFeed); - } - - public function unsetFormFeed() - { - $this->datatail = ''; - $this->setup->noFormFeed = 1; - } - - public function setCharset($charset = 'us-ascii') - { - $charset = strtolower($charset); - $this->charset = $charset; - $this->meta->charset = chr(0x47) // charset type | value-tag - . chr(0x00) . chr(0x12) // name-length - . "attributes-charset" // attributes-charset | name - . self::_giveMeStringLength($charset) // value-length - . $charset; // value - self::_putDebug(sprintf(_("Charset: %s") , $charset) , 2); - $this->setup->charset = 1; - } - - public function setLanguage($language = 'en_us') - { - $language = strtolower($language); - $this->meta->language = chr(0x48) // natural-language type | value-tag - . chr(0x00) . chr(0x1B) // name-length - . "attributes-natural-language" //attributes-natural-language - . self::_giveMeStringLength($language) // value-length - . $language; // value - self::_putDebug(sprintf(_("Language: %s") , $language) , 2); - $this->setup->language = 1; - } - - public function setDocumentFormat($mime_media_type = 'application/octet-stream') - { - self::setBinary(); - $length = chr(strlen($mime_media_type)); - while (strlen($length) < 2) $length = chr(0x00) . $length; - self::_putDebug(sprintf(_("mime type: %s") , $mime_media_type) , 2); - $this->meta->mime_media_type = chr(0x49) // document-format tag - . self::_giveMeStringLength('document-format') . 'document-format' // - . self::_giveMeStringLength($mime_media_type) . $mime_media_type; // value - $this->setup->mime_media_type = 1; - } - - // setDocumentFormat alias for backward compatibility - public function setMimeMediaType($mime_media_type = "application/octet-stream") - { - self::setDocumentFormat($mime_media_type); - } - - public function setCopies($nbrcopies = 1) - { - $this->meta->copies = ""; - if ($nbrcopies == 1 || !$nbrcopies) return true; - $copies = self::_integerBuild($nbrcopies); - $this->meta->copies = chr(0x21) // integer type | value-tag - . chr(0x00) . chr(0x06) // name-length - . "copies" // copies | name - . self::_giveMeStringLength($copies) // value-length - . $copies; - self::_putDebug(sprintf(_("Copies: %s") , $nbrcopies) , 2); - $this->setup->copies = 1; - } - - public function setDocumentName($document_name = "") - { - $this->meta->document_name = ""; - if (!$document_name) return true; - $document_name = substr($document_name, 0, 1023); - $length = strlen($document_name); - $length = chr($length); - while (strlen($length) < 2) $length = chr(0x00) . $length; - self::_putDebug(sprintf(_("document name: %s") , $document_name) , 2); - $this->meta->document_name = chr(0x41) // textWithoutLanguage tag - . chr(0x00) . chr(0x0d) // name-length - . "document-name" // mimeMediaType - . self::_giveMeStringLength($document_name) . $document_name; // value - - } - - public function setJobName($jobname = '', $absolute = false) - { - $this->meta->jobname = ''; - if ($jobname == '') - { - $this->meta->jobname = ''; - return true; - } - $postpend = date('-H:i:s-') . $this->_setJobId(); - if ($absolute) $postpend = ''; - if (isset($this->values->jobname) && $jobname == '(PHP)') - { - $jobname = $this->values->jobname; - } - $this->values->jobname = $jobname; - $jobname.= $postpend; - $this->meta->jobname = chr(0x42) // nameWithoutLanguage type || value-tag - . chr(0x00) . chr(0x08) // name-length - . "job-name" // job-name || name - . self::_giveMeStringLength($jobname) // value-length - . $jobname; // value - self::_putDebug(sprintf(_("Job name: %s") , $jobname) , 2); - $this->setup->jobname = 1; - } - - public function setUserName($username = 'PHP-SERVER') - { - $this->requesting_user = $username; - $this->meta->username = ''; - if (!$username) return true; - if ($username == 'PHP-SERVER' && isset($this->meta->username)) return TRUE; - /* - $value_length = 0x00; - for ($i = 0; $i < strlen($username); $i++) - { - $value_length+= 0x01; - } - $value_length = chr($value_length); - while (strlen($value_length) < 2) $value_length = chr(0x00) . $value_length; - */ - $this->meta->username = chr(0x42) // keyword type || value-tag - . chr(0x00) . chr(0x14) // name-length - . "requesting-user-name" - . self::_giveMeStringLength($username) // value-length - . $username; - self::_putDebug(sprintf(_("Username: %s") , $username) , 2); - $this->setup->username = 1; - } - - public function setAuthentification($username, $password) - { - self::setAuthentication($username, $password); - } - - public function setAuthentication($username, $password) - { - $this->password = $password; - $this->username = $username; - self::_putDebug(_("Setting password") , 2); - $this->setup->password = 1; - } - - public function setSides($sides = 2) - { - $this->meta->sides = ''; - if (!$sides) return true; - switch ($sides) - { - case 1: - $sides = "one-sided"; - break; - - case 2: - $sides = "two-sided-long-edge"; - break; - - case "2CE": - $sides = "two-sided-short-edge"; - break; - - default: - $sides = $sides; // yeah, what ? - break; - } - $this->meta->sides = chr(0x44) // keyword type | value-tag - . chr(0x00) . chr(0x05) // name-length - . "sides" // sides | name - . self::_giveMeStringLength($sides) // value-length - . $sides; // one-sided | value - self::_putDebug(sprintf(_("Sides value set to %s") , $sides) , 2); - } - - public function setFidelity() - { - // whether the server can't replace any attributes - // (eg, 2 sided print is not possible, - // so print one sided) and DO NOT THE JOB. - $this->meta->fidelity = chr(0x22) // boolean type | value-tag - . chr(0x00) . chr(0x16) // name-length - . "ipp-attribute-fidelity" // ipp-attribute-fidelity | name - . chr(0x00) . chr(0x01) // value-length - . chr(0x01); // true | value - self::_putDebug(_("Fidelity attribute is set (paranoid mode)") , 3); - } - - public function unsetFidelity() - { - // whether the server can replace any attributes - // (eg, 2 sided print is not possible, - // so print one sided) and DO THE JOB. - $this->meta->fidelity = chr(0x22) // boolean type | value-tag - . chr(0x00) . chr(0x16) // name-length - . "ipp-attribute-fidelity" // ipp-attribute-fidelity | name - . chr(0x00) . chr(0x01) // value-length - . chr(0x00); // false | value - self::_putDebug(_("Fidelity attribute is unset") , 2); - } - - public function setMessage($message = '') - { - $this->meta->message = ''; - if (!$message) return true; - $this->meta->message = - chr(0x41) // attribute type = textWithoutLanguage - . chr(0x00) - . chr(0x07) - . "message" - . self::_giveMeStringLength(substr($message, 0, 127)) - . substr($message, 0, 127); - self::_putDebug(sprintf(_('Setting message to "%s"') , $message) , 2); - } - - public function setPageRanges($page_ranges) - { - // $pages_ranges = string: "1:5 10:25 40:52 ..." - // to unset, specify an empty string. - $this->meta->page_range = ''; - if (!$page_ranges) return true; - $page_ranges = trim(str_replace("-", ":", $page_ranges)); - $first = true; - #$page_ranges = split(' ', $page_ranges); - $page_ranges = preg_split('# #', $page_ranges); - foreach($page_ranges as $page_range) - { - $value = self::_rangeOfIntegerBuild($page_range); - if ($first) - { - $this->meta->page_ranges .= - $this->tags_types['rangeOfInteger']['tag'] - . self::_giveMeStringLength('page-ranges') - . 'page-ranges' - . self::_giveMeStringLength($value) - . $value; - } - else - { - $this->meta->page_ranges .= - $this->tags_types['rangeOfInteger']['tag'] - . self::_giveMeStringLength('') - . self::_giveMeStringLength($value) - . $value; - $first = false; - } - } - } - - public function setAttribute($attribute, $values) - { - $operation_attributes_tags = array_keys($this->operation_tags); - $job_attributes_tags = array_keys($this->job_tags); - $printer_attributes_tags = array_keys($this->printer_tags); - self::unsetAttribute($attribute); - if (in_array($attribute, $operation_attributes_tags)) - { - if (!is_array($values)) - { - self::_setOperationAttribute($attribute, $values); - } - else - { - foreach($values as $value) - { - self::_setOperationAttribute($attribute, $value); - } - } - } - elseif (in_array($attribute, $job_attributes_tags)) - { - if (!is_array($values)) - { - self::_setJobAttribute($attribute, $values); - } - else - { - foreach($values as $value) - { - self::_setJobAttribute($attribute, $value); - } - } - } - elseif (in_array($attribute, $printer_attributes_tags)) - { - if (!is_array($values)) - { - self::_setPrinterAttribute($attribute, $values); - } - else - { - foreach($values as $value) - { - self::_setPrinterAttribute($attribute, $value); - } - } - } - else - { - trigger_error( - sprintf(_('SetAttribute: Tag "%s" is not a printer or a job attribute'), - $attribute) , E_USER_NOTICE); - self::_putDebug( - sprintf(_('SetAttribute: Tag "%s" is not a printer or a job attribute'), - $attribute) , 3); - self::_errorLog( - sprintf(_('SetAttribute: Tag "%s" is not a printer or a job attribute'), - $attribute) , 2); - return FALSE; - } - } - - public function unsetAttribute($attribute) - { - $operation_attributes_tags = array_keys($this->operation_tags); - $job_attributes_tags = array_keys($this->job_tags); - $printer_attributes_tags = array_keys($this->printer_tags); - if (in_array($attribute, $operation_attributes_tags)) - { - unset( - $this->operation_tags[$attribute]['value'], - $this->operation_tags[$attribute]['systag'] - ); - } - elseif (in_array($attribute, $job_attributes_tags)) - { - unset( - $this->job_tags[$attribute]['value'], - $this->job_tags[$attribute]['systag'] - ); - } - elseif (in_array($attribute, $printer_attributes_tags)) - { - unset( - $this->printer_tags[$attribute]['value'], - $this->printer_tags[$attribute]['systag'] - ); - } - else - { - trigger_error( - sprintf(_('unsetAttribute: Tag "%s" is not a printer or a job attribute'), - $attribute) , E_USER_NOTICE); - self::_putDebug( - sprintf(_('unsetAttribute: Tag "%s" is not a printer or a job attribute'), - $attribute) , 3); - self::_errorLog( - sprintf(_('unsetAttribute: Tag "%s" is not a printer or a job attribute'), - $attribute) , 2); - return FALSE; - } - return true; - } - - // - // LOGGING / DEBUGGING - // - - public function setLog($log_destination, $destination_type = 'file', $level = 2) - { - - if (is_string($log_destination) && !empty($log_destination)) - { - $this->log_destination = $log_destination; - } - - switch ($destination_type) - { - case 'file': - case 3: - $this->log_destination = $log_destination; - $this->log_type = 3; - break; - - case 'logger': - case 0: - $this->log_destination = ''; - $this->log_type = 0; - break; - - case 'e-mail': - case 1: - $this->log_destination = $log_destination; - $this->log_type = 1; - break; - } - $this->log_level = $level; - } - - public function printDebug() - { - for ($i = 0; $i < $this->debug_count; $i++) - { - echo $this->debug[$i], "\n"; - } - $this->debug = array(); - $this->debug_count = 0; - } - - public function getDebug() - { - $debug = ''; - for ($i = 0; $i < $this->debug_count; $i++) - { - $debug.= $this->debug[$i]; - } - $this->debug = array(); - $this->debug_count = 0; - return $debug; - } - - // - // OPERATIONS - // - - public function printJob() - { - // this BASIC version of printJob do not parse server - // output for job's attributes - self::_putDebug( - sprintf( - "************** Date: %s ***********", - date('Y-m-d H:i:s') - ) - ); - if (!$this->_stringJob()) return FALSE; - if (is_readable($this->data)) - { - self::_putDebug(_("Printing a FILE")); - $this->output = $this->stringjob; - if ($this->setup->datatype == "TEXT") - { - $this->output.= chr(0x16); - } - $post_values = array( - "Content-Type" => "application/ipp", - "Data" => $this->output, - "File" => $this->data - ); - if ($this->setup->datatype == "TEXT" && !isset($this->setup->noFormFeed)) - { - $post_values = array_merge( - $post_values, - array( - "Filetype" => "TEXT" - ) - ); - } - } - else - { - self::_putDebug(_("Printing DATA")); - $this->output = - $this->stringjob - . $this->datahead - . $this->data - . $this->datatail; - $post_values = array( - "Content-Type" => "application/ipp", - "Data" => $this->output - ); - } - if (self::_sendHttp($post_values, $this->paths["printers"])) - { - self::_parseServerOutput(); - } - if (isset($this->serveroutput) && isset($this->serveroutput->status)) - { - $this->status = array_merge($this->status, array( - $this->serveroutput->status - )); - if ($this->serveroutput->status == "successfull-ok") - { - self::_errorLog( - sprintf("printing job %s: ", $this->last_job) - . $this->serveroutput->status, - 3); - } - else - { - self::_errorLog( - sprintf("printing job: ", $this->last_job) - . $this->serveroutput->status, - 1); - } - return $this->serveroutput->status; - } - - $this->status = - array_merge($this->status, array("OPERATION FAILED")); - $this->jobs = - array_merge($this->jobs, array("")); - $this->jobs_uri = - array_merge($this->jobs_uri, array("")); - - self::_errorLog("printing job : OPERATION FAILED", 1); - return false; - } - - - /****************** - * - * PROTECTED FUNCTIONS - * - *******************/ - - // - // HTTP OUTPUT - // - - protected function _sendHttp($post_values, $uri) - { - /* - This function Copyright (C) 2005-2006 Thomas Harding, Manuel Lemos - */ - $this->response_completed[] = "no"; - unset($this->serverouptut); - self::_putDebug(_("Processing HTTP request") , 2); - $this->serveroutput->headers = array(); - $this->serveroutput->body = ""; - $http = new http_class; - if (!$this->unix) $http->host = $this->host; - else $http->host = "localhost"; - $http->with_exceptions = $this->with_exceptions; - if ($this->debug_http) - { - $http->debug = 1; - $http->html_debug = 0; - } - else - { - $http->debug = 0; - $http->html_debug = 0; - } - $url = "http://" . $this->host; - if ($this->ssl) $url = "https://" . $this->host; - if ($this->unix) $url = "unix://" . $this->host; - $http->port = $this->port; - $http->timeout = $this->http_timeout; - $http->data_timeout = $this->http_data_timeout; - $http->force_multipart_form_post = false; - $http->user = $this->username; - $http->password = $this->password; - $error = $http->GetRequestArguments($url, $arguments); - $arguments["RequestMethod"] = "POST"; - $arguments["Headers"] = array( - "Content-Type" => "application/ipp" + public $paths = array( + "root" => "/", + "admin" => "/admin/", + "printers" => "/printers/", + "jobs" => "/jobs/" ); - $arguments["BodyStream"] = array( - array( - "Data" => $post_values["Data"] - ) - ); - if (isset($post_values["File"])) $arguments["BodyStream"][] = array( - "File" => $post_values["File"] - ); - if (isset($post_values["FileType"]) - && !strcmp($post_values["FileType"], "TEXT")) - { - $arguments["BodyStream"][] = array("Data" => Chr(12)); - } - $arguments["RequestURI"] = $uri; - if ($this->with_exceptions && $this->handle_http_exceptions) - { - try - { - $success = $http->Open($arguments); - } - catch(httpException $e) - { - throw new ippException( - sprintf("http error: %s", $e->getMessage()), - $e->getErrno()); - } - } - else - { - $success = $http->Open($arguments); - } - if ($success[0] == true) - { - $success = $http->SendRequest($arguments); - if ($success[0] == true) - { - self::_putDebug("H T T P R E Q U E S T :"); - self::_putDebug("Request headers:"); - for (Reset($http->request_headers) , $header = 0; $header < count($http->request_headers); Next($http->request_headers) , $header++) + public $http_timeout = 30; // timeout at http connection (seconds) 0 => default => 30. + public $http_data_timeout = 30; // data reading timeout (milliseconds) 0 => default => 30. + public $ssl = false; + public $debug_level = 3; // max 3: almost silent + public $alert_on_end_tag; // debugging purpose: echo "END tag OK" if (1 and reads while end tag) + public $with_exceptions = 0; // compatibility mode for old scripts + public $handle_http_exceptions = 1; + + // readables variables + public $jobs = array(); + public $jobs_uri = array(); + public $status = array(); + public $response_completed = array(); + public $last_job = ""; + public $attributes; // object you can read: attributes after validateJob() + public $printer_attributes; // object you can read: printer's attributes after getPrinterAttributes() + public $job_attributes; // object you can read: last job attributes + public $jobs_attributes; // object you can read: jobs attributes after getJobs() + public $available_printers = array(); + public $printer_map = array(); + public $printers_uri = array(); + public $debug = array(); + public $response; + public $meta; + + // protected variables; + protected $log_level = 2; // max 3: very verbose + protected $log_type = 3; // 3: file | 1: e-mail | 0: logger + protected $log_destination; // e-mail or file + protected $serveroutput; + protected $setup; + protected $stringjob; + protected $data; + protected $debug_count = 0; + protected $username; + protected $charset; + protected $password; + protected $requesring_user; + protected $client_hostname = "localhost"; + protected $stream; + protected $host = "localhost"; + protected $port = "631"; + protected $requesting_user = ''; + protected $printer_uri; + protected $timeout = "20"; //20 secs + protected $errNo; + protected $errStr; + protected $datatype; + protected $datahead; + protected $datatail; + protected $operation_id; + protected $delay; + protected $error_generation; //devel feature + protected $debug_http = 0; + protected $no_disconnect; + protected $job_tags; + protected $operation_tags; + protected $index; + protected $collection; //RFC3382 + protected $collection_index; //RFC3382 + protected $collection_key = array(); //RFC3382 + protected $collection_depth = - 1; //RFC3382 + protected $end_collection = false; //RFC3382 + protected $collection_nbr = array(); //RFC3382 + protected $unix = false; // true -> use unix sockets instead of http + protected $output; + + public function __construct() { - $header_name = Key($http->request_headers); - if (GetType($http->request_headers[$header_name]) == "array") - { - for ($header_value = 0; $header_value < count($http->request_headers[$header_name]); $header_value++) - { - self::_putDebug($header_name . ": " . $http->request_headers[$header_name][$header_value]); - } - } - else - { - self::_putDebug($header_name . ": " . $http->request_headers[$header_name]); - } + $tz = getenv("date.timezone"); + if (!$tz) + { + $tz = @date_default_timezone_get(); + } + + date_default_timezone_set($tz); + $this->meta = new \stdClass(); + $this->setup = new \stdClass(); + $this->values = new \stdClass(); + $this->serveroutput = new \stdClass(); + $this->error_generation = new \stdClass(); + $this->_parsing = new \stdClass(); + self::_initTags(); } - self::_putDebug("Request body:"); - self::_putDebug( - htmlspecialchars($http->request_body) - . "*********** END REQUEST BODY *********" + + public function setPort($port = '631') + { + $this->port = $port; + self::_putDebug("Port is " . $this->port, 2); + } + + public function setUnix($socket = '/var/run/cups/cups.sock') + { + $this->host = $socket; + $this->unix = true; + self::_putDebug("Host is " . $this->host, 2); + } + + public function setHost($host = 'localhost') + { + $this->host = $host; + $this->unix = false; + self::_putDebug("Host is " . $this->host, 2); + } + + public function setTimeout($timeout) + { + $this->timeout = $timeout; + } + + public function setPrinterURI($uri) + { + $length = strlen($uri); + $length = chr($length); + while (strlen($length) < 2) $length = chr(0x00) . $length; + $this->meta->printer_uri = chr(0x45) // uri type | value-tag + . chr(0x00) . chr(0x0B) // name-length + . "printer-uri" // printer-uri | name + . $length . $uri; + $this->printer_uri = $uri; + self::_putDebug(sprintf(_("Printer URI: %s") , $uri) , 2); + $this->setup->uri = 1; + } + + public function setData($data) + { + $this->data = $data; + self::_putDebug("Data set", 2); + } + + public function setRawText() + { + $this->setup->datatype = 'TEXT'; + $this->meta->mime_media_type = ""; + $this->setup->mime_media_type = 1; + $this->datahead = chr(0x16); + if (is_readable($this->data)) + { + //It's a filename. Open and stream. + $data = fopen($this->data, "rb"); + while (!feof($data)) $output = fread($data, 8192); + } + else + { + $output = $this->data; + } + if (substr($output, -1, 1) != chr(0x0c)) { + if (!isset($this->setup->noFormFeed)) + { + $this->datatail = chr(0x0c); + } + } + self::_putDebug(_("Forcing data to be interpreted as RAW TEXT") , 2); + } + + public function unsetRawText() + { + $this->setup->datatype = 'BINARY'; + $this->datahead = ''; + $this->datatail = ''; + self::_putDebug(_("Unset forcing data to be interpreted as RAW TEXT") , 2); + } + + public function setBinary() + { + self::unsetRawText(); + } + + public function setFormFeed() + { + $this->datatail = "\r\n" . chr(0x0c); + unset($this->setup->noFormFeed); + } + + public function unsetFormFeed() + { + $this->datatail = ''; + $this->setup->noFormFeed = 1; + } + + public function setCharset($charset = 'utf-8') + { + $charset = strtolower($charset); + $this->charset = $charset; + $this->meta->charset = chr(0x47) // charset type | value-tag + . chr(0x00) . chr(0x12) // name-length + . "attributes-charset" // attributes-charset | name + . self::_giveMeStringLength($charset) // value-length + . $charset; // value + self::_putDebug(sprintf(_("Charset: %s") , $charset) , 2); + $this->setup->charset = 1; + } + + public function setLanguage($language = 'en_us') + { + $language = strtolower($language); + $this->meta->language = chr(0x48) // natural-language type | value-tag + . chr(0x00) . chr(0x1B) // name-length + . "attributes-natural-language" //attributes-natural-language + . self::_giveMeStringLength($language) // value-length + . $language; // value + self::_putDebug(sprintf(_("Language: %s") , $language) , 2); + $this->setup->language = 1; + } + + public function setDocumentFormat($mime_media_type = 'application/octet-stream') + { + self::setBinary(); + $length = chr(strlen($mime_media_type)); + while (strlen($length) < 2) $length = chr(0x00) . $length; + self::_putDebug(sprintf(_("mime type: %s") , $mime_media_type) , 2); + $this->meta->mime_media_type = chr(0x49) // document-format tag + . self::_giveMeStringLength('document-format') . 'document-format' // + . self::_giveMeStringLength($mime_media_type) . $mime_media_type; // value + $this->setup->mime_media_type = 1; + } + + // setDocumentFormat alias for backward compatibility + public function setMimeMediaType($mime_media_type = "application/octet-stream") + { + self::setDocumentFormat($mime_media_type); + } + + public function setCopies($nbrcopies = 1) + { + $this->meta->copies = ""; + + if ($nbrcopies == 1 || !$nbrcopies) + { + return true; + } + + $copies = self::_integerBuild($nbrcopies); + $this->meta->copies = chr(0x21) // integer type | value-tag + . chr(0x00) . chr(0x06) // name-length + . "copies" // copies | name + . self::_giveMeStringLength($copies) // value-length + . $copies; + self::_putDebug(sprintf(_("Copies: %s") , $nbrcopies) , 2); + $this->setup->copies = 1; + } + + public function setDocumentName($document_name = "") + { + $this->meta->document_name = ""; + if (!$document_name) { + return true; + } + $document_name = substr($document_name, 0, 1023); + $length = strlen($document_name); + $length = chr($length); + while (strlen($length) < 2) $length = chr(0x00) . $length; + self::_putDebug(sprintf(_("document name: %s") , $document_name) , 2); + $this->meta->document_name = chr(0x41) // textWithoutLanguage tag + . chr(0x00) . chr(0x0d) // name-length + . "document-name" // mimeMediaType + . self::_giveMeStringLength($document_name) . $document_name; // value + + } + + public function setJobName($jobname = '', $absolute = false) + { + $this->meta->jobname = ''; + if ($jobname == '') + { + $this->meta->jobname = ''; + return true; + } + $postpend = date('-H:i:s-') . $this->_setJobId(); + if ($absolute) { + $postpend = ''; + } + if (isset($this->values->jobname) && $jobname == '(PHP)') + { + $jobname = $this->values->jobname; + } + $this->values->jobname = $jobname; + $jobname.= $postpend; + $this->meta->jobname = chr(0x42) // nameWithoutLanguage type || value-tag + . chr(0x00) . chr(0x08) // name-length + . "job-name" // job-name || name + . self::_giveMeStringLength($jobname) // value-length + . $jobname; // value + self::_putDebug(sprintf(_("Job name: %s") , $jobname) , 2); + $this->setup->jobname = 1; + } + + public function setUserName($username = 'PHP-SERVER') + { + $this->requesting_user = $username; + $this->meta->username = ''; + if (!$username) { + return true; + } + if ($username == 'PHP-SERVER' && isset($this->meta->username)) { + return TRUE; + } + /* + $value_length = 0x00; + for ($i = 0; $i < strlen($username); $i++) + { + $value_length+= 0x01; + } + $value_length = chr($value_length); + while (strlen($value_length) < 2) $value_length = chr(0x00) . $value_length; + */ + $this->meta->username = chr(0x42) // keyword type || value-tag + . chr(0x00) . chr(0x14) // name-length + . "requesting-user-name" + . self::_giveMeStringLength($username) // value-length + . $username; + self::_putDebug(sprintf(_("Username: %s") , $username) , 2); + $this->setup->username = 1; + } + + public function setAuthentification($username, $password) + { + self::setAuthentication($username, $password); + } + + public function setAuthentication($username, $password) + { + $this->password = $password; + $this->username = $username; + self::_putDebug(_("Setting password") , 2); + $this->setup->password = 1; + } + + public function setSides($sides = 2) + { + $this->meta->sides = ''; + if (!$sides) + { + return true; + } + + switch ($sides) + { + case 1: + $sides = "one-sided"; + break; + + case 2: + $sides = "two-sided-long-edge"; + break; + + case "2CE": + $sides = "two-sided-short-edge"; + break; + } + + $this->meta->sides = chr(0x44) // keyword type | value-tag + . chr(0x00) . chr(0x05) // name-length + . "sides" // sides | name + . self::_giveMeStringLength($sides) // value-length + . $sides; // one-sided | value + self::_putDebug(sprintf(_("Sides value set to %s") , $sides) , 2); + } + + public function setFidelity() + { + // whether the server can't replace any attributes + // (eg, 2 sided print is not possible, + // so print one sided) and DO NOT THE JOB. + $this->meta->fidelity = chr(0x22) // boolean type | value-tag + . chr(0x00) . chr(0x16) // name-length + . "ipp-attribute-fidelity" // ipp-attribute-fidelity | name + . chr(0x00) . chr(0x01) // value-length + . chr(0x01); // true | value + self::_putDebug(_("Fidelity attribute is set (paranoid mode)") , 3); + } + + public function unsetFidelity() + { + // whether the server can replace any attributes + // (eg, 2 sided print is not possible, + // so print one sided) and DO THE JOB. + $this->meta->fidelity = chr(0x22) // boolean type | value-tag + . chr(0x00) . chr(0x16) // name-length + . "ipp-attribute-fidelity" // ipp-attribute-fidelity | name + . chr(0x00) . chr(0x01) // value-length + . chr(0x00); // false | value + self::_putDebug(_("Fidelity attribute is unset") , 2); + } + + public function setMessage($message = '') + { + $this->meta->message = ''; + if (!$message) { + return true; + } + $this->meta->message = + chr(0x41) // attribute type = textWithoutLanguage + . chr(0x00) + . chr(0x07) + . "message" + . self::_giveMeStringLength(substr($message, 0, 127)) + . substr($message, 0, 127); + self::_putDebug(sprintf(_('Setting message to "%s"') , $message) , 2); + } + + public function setPageRanges($page_ranges) + { + // $pages_ranges = string: "1:5 10:25 40:52 ..." + // to unset, specify an empty string. + $this->meta->page_range = ''; + if (!$page_ranges) { + return true; + } + $page_ranges = trim(str_replace("-", ":", $page_ranges)); + $first = true; + #$page_ranges = split(' ', $page_ranges); + $page_ranges = preg_split('# #', $page_ranges); + foreach($page_ranges as $page_range) + { + $value = self::_rangeOfIntegerBuild($page_range); + if ($first) + { + $this->meta->page_ranges .= + $this->tags_types['rangeOfInteger']['tag'] + . self::_giveMeStringLength('page-ranges') + . 'page-ranges' + . self::_giveMeStringLength($value) + . $value; + } + else + { + $this->meta->page_ranges .= + $this->tags_types['rangeOfInteger']['tag'] + . self::_giveMeStringLength('') + . self::_giveMeStringLength($value) + . $value; + $first = false; + } + } + } + + public function setAttribute($attribute, $values) + { + $operation_attributes_tags = array_keys($this->operation_tags); + $job_attributes_tags = array_keys($this->job_tags); + $printer_attributes_tags = array_keys($this->printer_tags); + self::unsetAttribute($attribute); + if (in_array($attribute, $operation_attributes_tags)) + { + if (!is_array($values)) + { + self::_setOperationAttribute($attribute, $values); + } + else + { + foreach($values as $value) + { + self::_setOperationAttribute($attribute, $value); + } + } + } + elseif (in_array($attribute, $job_attributes_tags)) + { + if (!is_array($values)) + { + self::_setJobAttribute($attribute, $values); + } + else + { + foreach($values as $value) + { + self::_setJobAttribute($attribute, $value); + } + } + } + elseif (in_array($attribute, $printer_attributes_tags)) + { + if (!is_array($values)) + { + self::_setPrinterAttribute($attribute, $values); + } + else + { + foreach($values as $value) + { + self::_setPrinterAttribute($attribute, $value); + } + } + } + else + { + trigger_error( + sprintf(_('SetAttribute: Tag "%s" is not a printer or a job attribute'), + $attribute) , E_USER_NOTICE); + self::_putDebug( + sprintf(_('SetAttribute: Tag "%s" is not a printer or a job attribute'), + $attribute) , 3); + self::_errorLog( + sprintf(_('SetAttribute: Tag "%s" is not a printer or a job attribute'), + $attribute) , 2); + return FALSE; + } + } + + public function unsetAttribute($attribute) + { + $operation_attributes_tags = array_keys($this->operation_tags); + $job_attributes_tags = array_keys($this->job_tags); + $printer_attributes_tags = array_keys($this->printer_tags); + if (in_array($attribute, $operation_attributes_tags)) + { + unset( + $this->operation_tags[$attribute]['value'], + $this->operation_tags[$attribute]['systag'] ); - $i = 0; - $headers = array(); - unset($this->serveroutput->headers); - $http->ReadReplyHeaders($headers); - self::_putDebug("H T T P R E S P O N S E :"); - self::_putDebug("Response headers:"); - for (Reset($headers) , $header = 0; $header < count($headers); Next($headers) , $header++) - { - $header_name = Key($headers); - if (GetType($headers[$header_name]) == "array") - { - for ($header_value = 0; $header_value < count($headers[$header_name]); $header_value++) - { - self::_putDebug($header_name . ": " . $headers[$header_name][$header_value]); - $this->serveroutput->headers[$i] = - $header_name . ": " - . $headers[$header_name][$header_value]; - $i++; - } - } - else - { - self::_putDebug($header_name . ": " . $headers[$header_name]); - $this->serveroutput->headers[$i] = - $header_name - . ": " - . $headers[$header_name]; - $i++; - } + } + elseif (in_array($attribute, $job_attributes_tags)) + { + unset( + $this->job_tags[$attribute]['value'], + $this->job_tags[$attribute]['systag'] + ); + } + elseif (in_array($attribute, $printer_attributes_tags)) + { + unset( + $this->printer_tags[$attribute]['value'], + $this->printer_tags[$attribute]['systag'] + ); + } + else + { + trigger_error( + sprintf(_('unsetAttribute: Tag "%s" is not a printer or a job attribute'), + $attribute) , E_USER_NOTICE); + self::_putDebug( + sprintf(_('unsetAttribute: Tag "%s" is not a printer or a job attribute'), + $attribute) , 3); + self::_errorLog( + sprintf(_('unsetAttribute: Tag "%s" is not a printer or a job attribute'), + $attribute) , 2); + return FALSE; + } + return true; } - self::_putDebug("\n\nResponse body:\n"); - $this->serveroutput->body = ""; - for (;;) - { - $http->ReadReplyBody($body, 1024); - if (strlen($body) == 0) break; - self::_putDebug(htmlentities($body)); - $this->serveroutput->body.= $body; - } - self::_putDebug("********* END RESPONSE BODY ********"); - } - } - $http->Close(); - return true; - } - - // - // INIT - // - - protected function _initTags() - { - $this->tags_types = array( - "unsupported" => array( - "tag" => chr(0x10) , - "build" => "" - ) , - "reserved" => array( - "tag" => chr(0x11) , - "build" => "" - ) , - "unknown" => array( - "tag" => chr(0x12) , - "build" => "" - ) , - "no-value" => array( - "tag" => chr(0x13) , - "build" => "no_value" - ) , - "integer" => array( - "tag" => chr(0x21) , - "build" => "integer" - ) , - "boolean" => array( - "tag" => chr(0x22) , - "build" => "boolean" - ) , - "enum" => array( - "tag" => chr(0x23) , - "build" => "enum" - ) , - "octetString" => array( - "tag" => chr(0x30) , - "build" => "octet_string" - ) , - "datetime" => array( - "tag" => chr(0x31) , - "build" => "datetime" - ) , - "resolution" => array( - "tag" => chr(0x32) , - "build" => "resolution" - ) , - "rangeOfInteger" => array( - "tag" => chr(0x33) , - "build" => "range_of_integers" - ) , - "textWithLanguage" => array( - "tag" => chr(0x35) , - "build" => "string" - ) , - "nameWithLanguage" => array( - "tag" => chr(0x36) , - "build" => "string" - ) , - /* - "text" => array ("tag" => chr(0x40), - "build" => "string"), - "text string" => array ("tag" => chr(0x40), - "build" => "string"), + // + // LOGGING / DEBUGGING + // + /** + * Sets log file destination. Creates the file if has permission. + * + * @param string $log_destination + * @param string $destination_type + * @param int $level + * + * @throws ippException */ - "textWithoutLanguage" => array( - "tag" => chr(0x41) , - "build" => "string" - ) , - "nameWithoutLanguage" => array( - "tag" => chr(0x42) , - "buid" => "string" - ) , - "keyword" => array( - "tag" => chr(0x44) , - "build" => "string" - ) , - "uri" => array( - "tag" => chr(0x45) , - "build" => "string" - ) , - "uriScheme" => array( - "tag" => chr(0x46) , - "build" => "string" - ) , - "charset" => array( - "tag" => chr(0x47) , - "build" => "string" - ) , - "naturalLanguage" => array( - "tag" => chr(0x48) , - "build" => "string" - ) , - "mimeMediaType" => array( - "tag" => chr(0x49) , - "build" => "string" - ) , - "extendedAttributes" => array( - "tag" => chr(0x7F) , - "build" => "extended" - ) , - ); - $this->operation_tags = array( - "compression" => array( - "tag" => "keyword" - ) , - "document-natural-language" => array( - "tag" => "naturalLanguage" - ) , - "job-k-octets" => array( - "tag" => "integer" - ) , - "job-impressions" => array( - "tag" => "integer" - ) , - "job-media-sheets" => array( - "tag" => "integer" - ) , - ); - $this->job_tags = array( - "job-priority" => array( - "tag" => "integer" - ) , - "job-hold-until" => array( - "tag" => "keyword" - ) , - "job-sheets" => array( - "tag" => "keyword" - ) , //banner page - "multiple-document-handling" => array( - "tag" => "keyword" - ) , - //"copies" => array("tag" => "integer"), - "finishings" => array( - "tag" => "enum" - ) , - //"page-ranges" => array("tag" => "rangeOfInteger"), // has its own function - //"sides" => array("tag" => "keyword"), // has its own function - "number-up" => array( - "tag" => "integer" - ) , - "orientation-requested" => array( - "tag" => "enum" - ) , - "media" => array( - "tag" => "keyword" - ) , - "printer-resolution" => array( - "tag" => "resolution" - ) , - "print-quality" => array( - "tag" => "enum" - ) , - "job-message-from-operator" => array( - "tag" => "textWithoutLanguage" - ) , - ); - $this->printer_tags = array( - "requested-attributes" => array( - "tag" => "keyword" - ) - ); - } - - // - // SETUP - // - - protected function _setOperationId() - { - $prepend = ''; - $this->operation_id+= 1; - $this->meta->operation_id = self::_integerBuild($this->operation_id); - self::_putDebug("operation id is: " . $this->operation_id, 2); - } - - protected function _setJobId() - { - $this->meta->jobid+= 1; - $prepend = ''; - $prepend_length = 4 - strlen($this->meta->jobid); - for ($i = 0; $i < $prepend_length; $i++) $prepend.= '0'; - return $prepend . $this->meta->jobid; - } - - protected function _setJobUri($job_uri) - { - $this->meta->job_uri = chr(0x45) // type uri - . chr(0x00) . chr(0x07) // name-length - . "job-uri" - //. chr(0x00).chr(strlen($job_uri)) - . self::_giveMeStringLength($job_uri) . $job_uri; - self::_putDebug("job-uri is: " . $job_uri, 2); - } - - // - // RESPONSE PARSING - // - - protected function _parseServerOutput() - { - $this->serveroutput->response = array(); - if (!self::_parseHttpHeaders()) return FALSE; - $this->_parsing->offset = 0; - self::_parseIppVersion(); - self::_parseStatusCode(); - self::_parseRequestID(); - $this->_parseResponse(); - //devel - self::_putDebug( - sprintf("***** IPP STATUS: %s ******", $this->serveroutput->status), - 4); - self::_putDebug("****** END OF OPERATION ****"); - return true; - } - - protected function _parseHttpHeaders() - { - $response = ""; - switch ($this->serveroutput->headers[0]) - { - case "http/1.1 200 ok: ": - $this->serveroutput->httpstatus = "HTTP/1.1 200 OK"; - $response = "OK"; - break; - - // primitive http/1.0 for Lexmark printers (from Rick Baril) - case "http/1.0 200 ok: ": - $this->serveroutput->httpstatus = "HTTP/1.0 200 OK"; - $response = "OK"; - break; - - case "http/1.1 100 continue: ": - $this->serveroutput->httpstatus = "HTTP/1.1 100 CONTINUE"; - $response = "OK"; - break; - - case "": - $this->serveroutput->httpstatus = "HTTP/1.1 000 No Response From Server"; - $this->serveroutput->status = "HTTP-ERROR-000_NO_RESPONSE_FROM_SERVER"; - trigger_error("No Response From Server", E_USER_WARNING); - self::_errorLog("No Response From Server", 1); - $this->disconnected = 1; - return FALSE; - break; - - default: - $server_response = preg_replace("/: $/", '', $this->serveroutput->headers[0]); - #$strings = split(' ', $server_response, 3); - $strings = preg_split('# #', $server_response, 3); - $errno = $strings[1]; - $string = strtoupper(str_replace(' ', '_', $strings[2])); - trigger_error( - sprintf(_("server responds %s") , $server_response), - E_USER_WARNING); - self::_errorLog("server responds " . $server_response, 1); - $this->serveroutput->httpstatus = - strtoupper($strings[0]) - . " " - . $errno - . " " - . ucfirst($strings[2]); - - $this->serveroutput->status = - "HTTP-ERROR-" - . $errno - . "-" - . $string; - $this->disconnected = 1; - return FALSE; - break; - } - unset($this->serveroutput->headers); - return TRUE; - } - - protected function _parseIppVersion() - { - $ippversion = - (ord($this->serveroutput->body[$this->_parsing->offset]) * 256) - + ord($this->serveroutput->body[$this->_parsing->offset + 1]); - switch ($ippversion) - { - case 0x0101: - $this->serveroutput->ipp_version = "1.1"; - break; - - default: - $this->serveroutput->ipp_version = - sprintf("%u.%u (Unknown)", - ord($this->serveroutput->body[$this->_parsing->offset]) * 256, - ord($this->serveroutput->body[$this->_parsing->offset + 1])); - break; - } - self::_putDebug("I P P R E S P O N S E :\n\n"); - self::_putDebug( - sprintf("IPP version %s%s: %s", - ord($this->serveroutput->body[$this->_parsing->offset]), - ord($this->serveroutput->body[$this->_parsing->offset + 1]), - $this->serveroutput->ipp_version)); - $this->_parsing->offset+= 2; - return; - } - - protected function _parseStatusCode() - { - $status_code = - (ord($this->serveroutput->body[$this->_parsing->offset]) * 256) - + ord($this->serveroutput->body[$this->_parsing->offset + 1]); - $this->serveroutput->status = "NOT PARSED"; - $this->_parsing->offset+= 2; - if (strlen($this->serveroutput->body) < $this->_parsing->offset) - { - return false; - } - if ($status_code < 0x00FF) - { - $this->serveroutput->status = "successfull"; - } - elseif ($status_code < 0x01FF) - { - $this->serveroutput->status = "informational"; - } - elseif ($status_code < 0x02FF) - { - $this->serveroutput->status = "redirection"; - } - elseif ($status_code < 0x04FF) - { - $this->serveroutput->status = "client-error"; - } - elseif ($status_code < 0x05FF) - { - $this->serveroutput->status = "server-error"; - } - switch ($status_code) - { - case 0x0000: - $this->serveroutput->status = "successfull-ok"; - break; - - case 0x0001: - $this->serveroutput->status = "successful-ok-ignored-or-substituted-attributes"; - break; - - case 0x002: - $this->serveroutput->status = "successful-ok-conflicting-attributes"; - break; - - case 0x0400: - $this->serveroutput->status = "client-error-bad-request"; - break; - - case 0x0401: - $this->serveroutput->status = "client-error-forbidden"; - break; - - case 0x0402: - $this->serveroutput->status = "client-error-not-authenticated"; - break; - - case 0x0403: - $this->serveroutput->status = "client-error-not-authorized"; - break; - - case 0x0404: - $this->serveroutput->status = "client-error-not-possible"; - break; - - case 0x0405: - $this->serveroutput->status = "client-error-timeout"; - break; - - case 0x0406: - $this->serveroutput->status = "client-error-not-found"; - break; - - case 0x0407: - $this->serveroutput->status = "client-error-gone"; - break; - - case 0x0408: - $this->serveroutput->status = "client-error-request-entity-too-large"; - break; - - case 0x0409: - $this->serveroutput->status = "client-error-request-value-too-long"; - break; - - case 0x040A: - $this->serveroutput->status = "client-error-document-format-not-supported"; - break; - - case 0x040B: - $this->serveroutput->status = "client-error-attributes-or-values-not-supported"; - break; - - case 0x040C: - $this->serveroutput->status = "client-error-uri-scheme-not-supported"; - break; - - case 0x040D: - $this->serveroutput->status = "client-error-charset-not-supported"; - break; - - case 0x040E: - $this->serveroutput->status = "client-error-conflicting-attributes"; - break; - - case 0x040F: - $this->serveroutput->status = "client-error-compression-not-supported"; - break; - - case 0x0410: - $this->serveroutput->status = "client-error-compression-error"; - break; - - case 0x0411: - $this->serveroutput->status = "client-error-document-format-error"; - break; - - case 0x0412: - $this->serveroutput->status = "client-error-document-access-error"; - break; - - case 0x0413: // RFC3380 - $this->serveroutput->status = "client-error-attributes-not-settable"; - break; - - case 0x0500: - $this->serveroutput->status = "server-error-internal-error"; - break; - - case 0x0501: - $this->serveroutput->status = "server-error-operation-not-supported"; - break; - - case 0x0502: - $this->serveroutput->status = "server-error-service-unavailable"; - break; - - case 0x0503: - $this->serveroutput->status = "server-error-version-not-supported"; - break; - - case 0x0504: - $this->serveroutput->status = "server-error-device-error"; - break; - - case 0x0505: - $this->serveroutput->status = "server-error-temporary-error"; - break; - - case 0x0506: - $this->serveroutput->status = "server-error-not-accepting-jobs"; - break; - - case 0x0507: - $this->serveroutput->status = "server-error-busy"; - break; - - case 0x0508: - $this->serveroutput->status = "server-error-job-canceled"; - break; - - case 0x0509: - $this->serveroutput->status = "server-error-multiple-document-jobs-not-supported"; - break; - - default: - break; - } - self::_putDebug( - sprintf( - "status-code: %s%s: %s ", - $this->serveroutput->body[$this->_parsing->offset], - $this->serveroutput->body[$this->_parsing->offset + 1], - $this->serveroutput->status), - 4); - return; - } - - protected function _parseRequestID() - { - $this->serveroutput->request_id = - self::_interpretInteger( - substr($this->serveroutput->body, $this->_parsing->offset, 4) - ); - self::_putDebug("request-id " . $this->serveroutput->request_id, 2); - $this->_parsing->offset+= 4; - return; - } - - protected function _interpretInteger($value) - { - // they are _signed_ integers - $value_parsed = 0; - for ($i = strlen($value); $i > 0; $i --) - { - $value_parsed += - ( - (1 << (($i - 1) * 8)) - * - ord($value[strlen($value) - $i]) - ); - - } - if ($value_parsed >= 2147483648) - { - $value_parsed -= 4294967296; - } - return $value_parsed; - } - - protected function _parseResponse() - { - } - - // - // REQUEST BUILDING - // - - protected function _stringJob() - { - if (!isset($this->setup->charset)) self::setCharset('us-ascii'); - if (!isset($this->setup->datatype)) self::setBinary(); - if (!isset($this->setup->uri)) - { - $this->getPrinters(); - unset($this->jobs[count($this->jobs) - 1]); - unset($this->jobs_uri[count($this->jobs_uri) - 1]); - unset($this->status[count($this->status) - 1]); - if (array_key_exists(0, $this->available_printers)) - { - self::setPrinterURI($this->available_printers[0]); - } - else - { - trigger_error( - _("_stringJob: Printer URI is not set: die"), - E_USER_WARNING); - self::_putDebug(_("_stringJob: Printer URI is not set: die") , 4); - self::_errorLog(" Printer URI is not set, die", 2); - return FALSE; - } - } - if (!isset($this->setup->copies)) self::setCopies(1); - if (!isset($this->setup->language)) self::setLanguage('en_us'); - if (!isset($this->setup->mime_media_type)) self::setMimeMediaType(); - if (!isset($this->setup->jobname)) self::setJobName(); - unset($this->setup->jobname); - if (!isset($this->meta->username)) self::setUserName(); - if (!isset($this->meta->fidelity)) $this->meta->fidelity = ''; - if (!isset($this->meta->document_name)) $this->meta->document_name = ''; - if (!isset($this->meta->sides)) $this->meta->sides = ''; - if (!isset($this->meta->page_ranges)) $this->meta->page_ranges = ''; - $jobattributes = ''; - $operationattributes = ''; - $printerattributes = ''; - $this->_buildValues($operationattributes, $jobattributes, $printerattributes); - self::_setOperationId(); - if (!isset($this->error_generation->request_body_malformed)) - { - $this->error_generation->request_body_malformed = ""; - } - $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number - . chr(0x00) . chr(0x02) // Print-Job | operation-id - . $this->meta->operation_id // request-id - . chr(0x01) // start operation-attributes | operation-attributes-tag - . $this->meta->charset - . $this->meta->language - . $this->meta->printer_uri - . $this->meta->username - . $this->meta->jobname - . $this->meta->fidelity - . $this->meta->document_name - . $this->meta->mime_media_type - . $operationattributes; - if ($this->meta->copies || $this->meta->sides || $this->meta->page_ranges || !empty($jobattributes)) - { - $this->stringjob .= - chr(0x02) // start job-attributes | job-attributes-tag - . $this->meta->copies - . $this->meta->sides - . $this->meta->page_ranges - . $jobattributes - ; - } - $this->stringjob.= chr(0x03); // end-of-attributes | end-of-attributes-tag - self::_putDebug( - sprintf(_("String sent to the server is: %s"), - $this->stringjob) - ); - return TRUE; - } - - protected function _buildValues(&$operationattributes, &$jobattributes, &$printerattributes) - { - $operationattributes = ''; - foreach($this->operation_tags as $key => $values) - { - $item = 0; - if (array_key_exists('value', $values)) - { - foreach($values['value'] as $item_value) + public function setLog($log_destination, $destination_type = 'file', $level = 2) { - if ($item == 0) - { - $operationattributes .= - $values['systag'] - . self::_giveMeStringLength($key) - . $key - . self::_giveMeStringLength($item_value) - . $item_value; - } - else - { - $operationattributes .= - $values['systag'] - . self::_giveMeStringLength('') - . self::_giveMeStringLength($item_value) - . $item_value; - } - $item++; + if (!file_exists($log_destination) && is_writable(dirname($log_destination))) + { + touch($log_destination); + chmod($log_destination, 0777); + } + + switch ($destination_type) + { + case 'file': + case 3: + $this->log_destination = $log_destination; + $this->log_type = 3; + break; + + case 'logger': + case 0: + $this->log_destination = ''; + $this->log_type = 0; + break; + + case 'e-mail': + case 1: + $this->log_destination = $log_destination; + $this->log_type = 1; + break; + } + $this->log_level = $level; } - } - } - $jobattributes = ''; - foreach($this->job_tags as $key => $values) - { - $item = 0; - if (array_key_exists('value', $values)) - { - foreach($values['value'] as $item_value) + + public function printDebug() { - if ($item == 0) - { - $jobattributes .= - $values['systag'] - . self::_giveMeStringLength($key) - . $key - . self::_giveMeStringLength($item_value) - . $item_value; - } - else - { - $jobattributes .= - $values['systag'] - . self::_giveMeStringLength('') - . self::_giveMeStringLength($item_value) - . $item_value; - } - $item++; + for ($i = 0; $i < $this->debug_count; $i++) + { + echo $this->debug[$i], "\n"; + } + $this->debug = array(); + $this->debug_count = 0; } - } - } - $printerattributes = ''; - foreach($this->printer_tags as $key => $values) - { - $item = 0; - if (array_key_exists('value', $values)) - { - foreach($values['value'] as $item_value) + + public function getDebug() { - if ($item == 0) - { - $printerattributes .= - $values['systag'] - . self::_giveMeStringLength($key) - . $key - . self::_giveMeStringLength($item_value) - . $item_value; - } - else - { - $printerattributes .= - $values['systag'] - . self::_giveMeStringLength('') - . self::_giveMeStringLength($item_value) - . $item_value; - } - $item++; + $debug = ''; + for ($i = 0; $i < $this->debug_count; $i++) + { + $debug.= $this->debug[$i]; + } + $this->debug = array(); + $this->debug_count = 0; + return $debug; } - } - } - reset($this->job_tags); - reset($this->operation_tags); - reset($this->printer_tags); - return true; - } - protected function _giveMeStringLength($string) - { - $length = strlen($string); - if ($length > ((0xFF << 8) + 0xFF) ) - { - $errmsg = sprintf ( - _('max string length for an ipp meta-information = %d, while here %d'), - ((0xFF << 8) + 0xFF), $length); - - if ($this->with_exceptions) - { - throw new ippException($errmsg); - } - else - { - trigger_error ($errmsg, E_USER_ERROR); - } - } - $int1 = $length & 0xFF; - $length -= $int1; - $length = $length >> 8; - $int2 = $length & 0xFF; - return chr($int2) . chr($int1); - } - - protected function _enumBuild($tag, $value) - { - switch ($tag) - { - case "orientation-requested": - switch ($value) + // + // OPERATIONS + // + public function printJob() { - case 'portrait': - $value = chr(3); - break; - - case 'landscape': - $value = chr(4); - break; - - case 'reverse-landscape': - $value = chr(5); - break; - - case 'reverse-portrait': - $value = chr(6); - break; - } - break; - - case "print-quality": - switch ($value) - { - case 'draft': - $value = chr(3); - break; - - case 'normal': - $value = chr(4); - break; - - case 'high': - $value = chr(5); - break; - } - break; - - case "finishing": - switch ($value) - { - case 'none': - $value = chr(3); - break; - - case 'staple': - $value = chr(4); - break; - - case 'punch': - $value = chr(5); - break; - - case 'cover': - $value = chr(6); - break; - - case 'bind': - $value = chr(7); - break; - - case 'saddle-stitch': - $value = chr(8); - break; - - case 'edge-stitch': - $value = chr(9); - break; - - case 'staple-top-left': - $value = chr(20); - break; - - case 'staple-bottom-left': - $value = chr(21); - break; - - case 'staple-top-right': - $value = chr(22); - break; - - case 'staple-bottom-right': - $value = chr(23); - break; - - case 'edge-stitch-left': - $value = chr(24); - break; - - case 'edge-stitch-top': - $value = chr(25); - break; - - case 'edge-stitch-right': - $value = chr(26); - break; - - case 'edge-stitch-bottom': - $value = chr(27); - break; - - case 'staple-dual-left': - $value = chr(28); - break; - - case 'staple-dual-top': - $value = chr(29); - break; - - case 'staple-dual-right': - $value = chr(30); - break; - - case 'staple-dual-bottom': - $value = chr(31); - break; - } - break; - } - $prepend = ''; - while ((strlen($value) + strlen($prepend)) < 4) - { - $prepend .= chr(0); - } - return $prepend . $value; - } - - protected function _integerBuild($value) - { - if ($value >= 2147483647 || $value < - 2147483648) - { - trigger_error( - _("Values must be between -2147483648 and 2147483647: assuming '0'") , E_USER_WARNING); - return chr(0x00) . chr(0x00) . chr(0x00) . chr(0x00); - } - $initial_value = $value; - $int1 = $value & 0xFF; - $value -= $int1; - $value = $value >> 8; - $int2 = $value & 0xFF; - $value-= $int2; - $value = $value >> 8; - $int3 = $value & 0xFF; - $value-= $int3; - $value = $value >> 8; - $int4 = $value & 0xFF; //64bits - if ($initial_value < 0) $int4 = chr($int4) | chr(0x80); - else $int4 = chr($int4); - $value = $int4 . chr($int3) . chr($int2) . chr($int1); - return $value; - } - - protected function _rangeOfIntegerBuild($integers) - { - #$integers = split(":", $integers); - $integers = preg_split("#:#", $integers); - for ($i = 0; $i < 2; $i++) $outvalue[$i] = self::_integerBuild($integers[$i]); - return $outvalue[0] . $outvalue[1]; - } - - protected function _setJobAttribute($attribute, $value) - { - //used by setAttribute - $tag_type = $this->job_tags[$attribute]['tag']; - switch ($tag_type) - { - case 'integer': - $this->job_tags[$attribute]['value'][] = self::_integerBuild($value); - break; - - case 'nameWithoutLanguage': - case 'nameWithLanguage': - case 'textWithoutLanguage': - case 'textWithLanguage': - case 'keyword': - case 'naturalLanguage': - $this->job_tags[$attribute]['value'][] = $value; - break; - - case 'enum': - $value = $this->_enumBuild($attribute, $value); // may be overwritten by children - $this->job_tags[$attribute]['value'][] = $value; - break; - - case 'rangeOfInteger': - // $value have to be: INT1:INT2 , eg 100:1000 - $this->job_tags[$attribute]['value'][] = self::_rangeOfIntegerBuild($value); - break; - - case 'resolution': - if (preg_match("#dpi#", $value)) $unit = chr(0x3); - if (preg_match("#dpc#", $value)) $unit = chr(0x4); - $search = array( - "#(dpi|dpc)#", - '#(x|-)#' + // this BASIC version of printJob do not parse server + // output for job's attributes + self::_putDebug( + sprintf( + "************** Date: %s ***********", + date('Y-m-d H:i:s') + ) + ); + if (!$this->_stringJob()) { + return FALSE; + } + if (is_readable($this->data)) + { + self::_putDebug(_("Printing a FILE")); + $this->output = $this->stringjob; + if ($this->setup->datatype == "TEXT") + { + $this->output.= chr(0x16); + } + $post_values = array( + "Content-Type" => "application/ipp", + "Data" => $this->output, + "File" => $this->data ); - $replace = array( - "", - ":" - ); - $value = self::_rangeOfIntegerBuild(preg_replace($search, $replace, $value)) . $unit; - $this->job_tags[$attribute]['value'][] = $value; - break; + if ($this->setup->datatype == "TEXT" && !isset($this->setup->noFormFeed)) + { + $post_values = array_merge( + $post_values, + array( + "Filetype" => "TEXT" + ) + ); + } + } + else + { + self::_putDebug(_("Printing DATA")); + $this->output = + $this->stringjob + . $this->datahead + . $this->data + . $this->datatail; + $post_values = array( + "Content-Type" => "application/ipp", + "Data" => $this->output + ); + } + if (self::_sendHttp($post_values, $this->paths["printers"])) + { + self::_parseServerOutput(); + } + if (isset($this->serveroutput) && isset($this->serveroutput->status)) + { + $this->status = array_merge($this->status, array( + $this->serveroutput->status + )); + if ($this->serveroutput->status == "successfull-ok") + { + self::_errorLog( + sprintf("printing job %s: ", $this->last_job) + . $this->serveroutput->status, + 3); + } + else + { + self::_errorLog( + sprintf("printing job: ", $this->last_job) + . $this->serveroutput->status, + 1); + } + return $this->serveroutput->status; + } - default: - trigger_error(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , E_USER_NOTICE); - self::_putDebug(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2); - self::_errorLog(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2); - return FALSE; - break; - } - $this->job_tags[$attribute]['systag'] = $this->tags_types[$tag_type]['tag']; - } + $this->status = + array_merge($this->status, array("OPERATION FAILED")); + $this->jobs = + array_merge($this->jobs, array("")); + $this->jobs_uri = + array_merge($this->jobs_uri, array("")); - protected function _setOperationAttribute($attribute, $value) - { - //used by setAttribute - $tag_type = $this->operation_tags[$attribute]['tag']; - switch ($tag_type) - { - case 'integer': - $this->operation_tags[$attribute]['value'][] = self::_integerBuild($value); - break; + self::_errorLog("printing job : OPERATION FAILED", 1); + return false; + } - case 'keyword': - case 'naturalLanguage': - $this->operation_tags[$attribute]['value'][] = $value; - break; + // + // HTTP OUTPUT + // + protected function _sendHttp($post_values, $uri) + { + /* + This function Copyright (C) 2005-2006 Thomas Harding, Manuel Lemos + */ + $this->response_completed[] = "no"; + unset($this->serverouptut); + self::_putDebug(_("Processing HTTP request") , 2); + $this->serveroutput->headers = array(); + $this->serveroutput->body = ""; + $http = new http_class; + if (!$this->unix) { + $http->host = $this->host; + } + else { + $http->host = "localhost"; + } + $http->with_exceptions = $this->with_exceptions; + if ($this->debug_http) + { + $http->debug = 1; + $http->html_debug = 0; + } + else + { + $http->debug = 0; + $http->html_debug = 0; + } + $url = "http://" . $this->host; + if ($this->ssl) { + $url = "https://" . $this->host; + } + if ($this->unix) { + $url = "unix://" . $this->host; + } + $http->port = $this->port; + $http->timeout = $this->http_timeout; + $http->data_timeout = $this->http_data_timeout; + $http->force_multipart_form_post = false; + $http->user = $this->username; + $http->password = $this->password; + $error = $http->GetRequestArguments($url, $arguments); + $arguments["RequestMethod"] = "POST"; + $arguments["Headers"] = array( + "Content-Type" => "application/ipp" + ); + $arguments["BodyStream"] = array( + array( + "Data" => $post_values["Data"] + ) + ); + if (isset($post_values["File"])) { + $arguments["BodyStream"][] = array( + "File" => $post_values["File"] + ); + } + if (isset($post_values["FileType"]) + && !strcmp($post_values["FileType"], "TEXT") + ) + { + $arguments["BodyStream"][] = array("Data" => Chr(12)); + } + $arguments["RequestURI"] = $uri; + if ($this->with_exceptions && $this->handle_http_exceptions) + { + try + { + $success = $http->Open($arguments); + } + catch(httpException $e) + { + throw new ippException( + sprintf("http error: %s", $e->getMessage()), + $e->getErrno()); + } + } + else + { + $success = $http->Open($arguments); + } + if ($success[0] == true) + { + $success = $http->SendRequest($arguments); + if ($success[0] == true) + { + self::_putDebug("H T T P R E Q U E S T :"); + self::_putDebug("Request headers:"); + for (Reset($http->request_headers) , $header = 0; $header < count($http->request_headers); Next($http->request_headers) , $header++) + { + $header_name = Key($http->request_headers); + if (GetType($http->request_headers[$header_name]) == "array") + { + for ($header_value = 0; $header_value < count($http->request_headers[$header_name]); $header_value++) + { + self::_putDebug($header_name . ": " . $http->request_headers[$header_name][$header_value]); + } + } + else + { + self::_putDebug($header_name . ": " . $http->request_headers[$header_name]); + } + } + self::_putDebug("Request body:"); + self::_putDebug( + htmlspecialchars($http->request_body) + . "*********** END REQUEST BODY *********" + ); + $i = 0; + $headers = array(); + unset($this->serveroutput->headers); + $http->ReadReplyHeaders($headers); + self::_putDebug("H T T P R E S P O N S E :"); + self::_putDebug("Response headers:"); + for (Reset($headers) , $header = 0; $header < count($headers); Next($headers) , $header++) + { + $header_name = Key($headers); + if (GetType($headers[$header_name]) == "array") + { + for ($header_value = 0; $header_value < count($headers[$header_name]); $header_value++) + { + self::_putDebug($header_name . ": " . $headers[$header_name][$header_value]); + $this->serveroutput->headers[$i] = + $header_name . ": " + . $headers[$header_name][$header_value]; + $i++; + } + } + else + { + self::_putDebug($header_name . ": " . $headers[$header_name]); + $this->serveroutput->headers[$i] = + $header_name + . ": " + . $headers[$header_name]; + $i++; + } + } + self::_putDebug("\n\nResponse body:\n"); + $this->serveroutput->body = ""; + for (;;) + { + $http->ReadReplyBody($body, 1024); + if (strlen($body) == 0) { + break; + } - default: - trigger_error(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , E_USER_NOTICE); - self::_putDebug(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2); - self::_errorLog(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2); - return FALSE; - break; - } - $this->operation_tags[$attribute]['systag'] = $this->tags_types[$tag_type]['tag']; - } + self::_putDebug(htmlentities($body)); + $this->serveroutput->body.= $body; + } + self::_putDebug("********* END RESPONSE BODY ********"); + } + } + $http->Close(); + return true; + } - protected function _setPrinterAttribute($attribute, $value) - { - //used by setAttribute - $tag_type = $this->printer_tags[$attribute]['tag']; - switch ($tag_type) - { - case 'integer': - $this->printer_tags[$attribute]['value'][] = self::_integerBuild($value); - break; + // + // INIT + // + protected function _initTags() + { + $this->tags_types = array( + "unsupported" => array( + "tag" => chr(0x10) , + "build" => "" + ) , + "reserved" => array( + "tag" => chr(0x11) , + "build" => "" + ) , + "unknown" => array( + "tag" => chr(0x12) , + "build" => "" + ) , + "no-value" => array( + "tag" => chr(0x13) , + "build" => "no_value" + ) , + "integer" => array( + "tag" => chr(0x21) , + "build" => "integer" + ) , + "boolean" => array( + "tag" => chr(0x22) , + "build" => "boolean" + ) , + "enum" => array( + "tag" => chr(0x23) , + "build" => "enum" + ) , + "octetString" => array( + "tag" => chr(0x30) , + "build" => "octet_string" + ) , + "datetime" => array( + "tag" => chr(0x31) , + "build" => "datetime" + ) , + "resolution" => array( + "tag" => chr(0x32) , + "build" => "resolution" + ) , + "rangeOfInteger" => array( + "tag" => chr(0x33) , + "build" => "range_of_integers" + ) , + "textWithLanguage" => array( + "tag" => chr(0x35) , + "build" => "string" + ) , + "nameWithLanguage" => array( + "tag" => chr(0x36) , + "build" => "string" + ) , + /* + "text" => array ("tag" => chr(0x40), + "build" => "string"), + "text string" => array ("tag" => chr(0x40), + "build" => "string"), + */ + "textWithoutLanguage" => array( + "tag" => chr(0x41) , + "build" => "string" + ) , + "nameWithoutLanguage" => array( + "tag" => chr(0x42) , + "buid" => "string" + ) , + "keyword" => array( + "tag" => chr(0x44) , + "build" => "string" + ) , + "uri" => array( + "tag" => chr(0x45) , + "build" => "string" + ) , + "uriScheme" => array( + "tag" => chr(0x46) , + "build" => "string" + ) , + "charset" => array( + "tag" => chr(0x47) , + "build" => "string" + ) , + "naturalLanguage" => array( + "tag" => chr(0x48) , + "build" => "string" + ) , + "mimeMediaType" => array( + "tag" => chr(0x49) , + "build" => "string" + ) , + "extendedAttributes" => array( + "tag" => chr(0x7F) , + "build" => "extended" + ) , + ); + $this->operation_tags = array( + "compression" => array( + "tag" => "keyword" + ) , + "document-natural-language" => array( + "tag" => "naturalLanguage" + ) , + "job-k-octets" => array( + "tag" => "integer" + ) , + "job-impressions" => array( + "tag" => "integer" + ) , + "job-media-sheets" => array( + "tag" => "integer" + ) , + ); + $this->job_tags = array( + "job-priority" => array( + "tag" => "integer" + ) , + "job-hold-until" => array( + "tag" => "keyword" + ) , + "job-sheets" => array( + "tag" => "keyword" + ) , //banner page + "multiple-document-handling" => array( + "tag" => "keyword" + ) , + //"copies" => array("tag" => "integer"), + "finishings" => array( + "tag" => "enum" + ) , + //"page-ranges" => array("tag" => "rangeOfInteger"), // has its own function + //"sides" => array("tag" => "keyword"), // has its own function + "number-up" => array( + "tag" => "integer" + ) , + "orientation-requested" => array( + "tag" => "enum" + ) , + "media" => array( + "tag" => "keyword" + ) , + "printer-resolution" => array( + "tag" => "resolution" + ) , + "print-quality" => array( + "tag" => "enum" + ) , + "job-message-from-operator" => array( + "tag" => "textWithoutLanguage" + ) , + ); + $this->printer_tags = array( + "requested-attributes" => array( + "tag" => "keyword" + ) + ); + } - case 'keyword': - case 'naturalLanguage': - $this->printer_tags[$attribute]['value'][] = $value; - break; + // + // SETUP + // + protected function _setOperationId() + { + $prepend = ''; + $this->operation_id+= 1; + $this->meta->operation_id = self::_integerBuild($this->operation_id); + self::_putDebug("operation id is: " . $this->operation_id, 2); + } - default: - trigger_error(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , E_USER_NOTICE); - self::_putDebug(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2); - self::_errorLog(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2); - return FALSE; - break; - } - $this->printer_tags[$attribute]['systag'] = $this->tags_types[$tag_type]['tag']; - } + protected function _setJobId() + { + $this->meta->jobid+= 1; + $prepend = ''; + $prepend_length = 4 - strlen($this->meta->jobid); + for ($i = 0; $i < $prepend_length; $i++) { + $prepend.= '0'; + } + return $prepend . $this->meta->jobid; + } - // - // DEBUGGING - // - protected function _putDebug($string, $level = 1) - { - if ($level === false) return; - if ($level < $this->debug_level) return; - $this->debug[$this->debug_count] = substr($string, 0, 1024); - $this->debug_count++; - //$this->debug .= substr($string,0,1024); + protected function _setJobUri($job_uri) + { + $this->meta->job_uri = chr(0x45) // type uri + . chr(0x00) . chr(0x07) // name-length + . "job-uri" + //. chr(0x00).chr(strlen($job_uri)) + . self::_giveMeStringLength($job_uri) . $job_uri; + self::_putDebug("job-uri is: " . $job_uri, 2); + } - } + // + // RESPONSE PARSING + // + protected function _parseServerOutput() + { + $this->serveroutput->response = array(); + if (!self::_parseHttpHeaders()) { + return FALSE; + } + $this->_parsing->offset = 0; + self::_parseIppVersion(); + self::_parseStatusCode(); + self::_parseRequestID(); + $this->_parseResponse(); + //devel + self::_putDebug( + sprintf("***** IPP STATUS: %s ******", $this->serveroutput->status), + 4); + self::_putDebug("****** END OF OPERATION ****"); + return true; + } - // - // LOGGING - // - protected function _errorLog($string_to_log, $level) - { - if ($level < $this->log_level) return; - $string = sprintf('%s : %s:%s user %s : %s', basename($_SERVER['PHP_SELF']) , $this->host, $this->port, $this->requesting_user, $string_to_log); - if ($this->log_type == 0) - { - error_log($string); - return; - } - $string = sprintf("%s %s Host %s:%s user %s : %s\n", date('M d H:i:s') , basename($_SERVER['PHP_SELF']) , $this->host, $this->port, $this->requesting_user, $string_to_log); - error_log($string, $this->log_type, $this->log_destination); - return; - } + protected function _parseHttpHeaders() + { + $response = ""; + switch ($this->serveroutput->headers[0]) + { + case "http/1.1 200 ok: ": + $this->serveroutput->httpstatus = "HTTP/1.1 200 OK"; + $response = "OK"; + break; -}; -/* - * Local variables: - * mode: php - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ -?> + // primitive http/1.0 for Lexmark printers (from Rick Baril) + case "http/1.0 200 ok: ": + $this->serveroutput->httpstatus = "HTTP/1.0 200 OK"; + $response = "OK"; + break; + + case "http/1.1 100 continue: ": + $this->serveroutput->httpstatus = "HTTP/1.1 100 CONTINUE"; + $response = "OK"; + break; + + case "": + $this->serveroutput->httpstatus = "HTTP/1.1 000 No Response From Server"; + $this->serveroutput->status = "HTTP-ERROR-000_NO_RESPONSE_FROM_SERVER"; + trigger_error("No Response From Server", E_USER_WARNING); + self::_errorLog("No Response From Server", 1); + $this->disconnected = 1; + return FALSE; + break; + + default: + $server_response = preg_replace("/: $/", '', $this->serveroutput->headers[0]); + #$strings = split(' ', $server_response, 3); + $strings = preg_split('# #', $server_response, 3); + $errno = $strings[1]; + $string = strtoupper(str_replace(' ', '_', $strings[2])); + trigger_error( + sprintf(_("server responds %s") , $server_response), + E_USER_WARNING); + self::_errorLog("server responds " . $server_response, 1); + $this->serveroutput->httpstatus = + strtoupper($strings[0]) + . " " + . $errno + . " " + . ucfirst($strings[2]); + + $this->serveroutput->status = + "HTTP-ERROR-" + . $errno + . "-" + . $string; + $this->disconnected = 1; + return FALSE; + break; + } + unset($this->serveroutput->headers); + return TRUE; + } + + protected function _parseIppVersion() + { + $ippversion = + (ord($this->serveroutput->body[$this->_parsing->offset]) * 256) + + ord($this->serveroutput->body[$this->_parsing->offset + 1]); + switch ($ippversion) + { + case 0x0101: + $this->serveroutput->ipp_version = "1.1"; + break; + + default: + $this->serveroutput->ipp_version = + sprintf("%u.%u (Unknown)", + ord($this->serveroutput->body[$this->_parsing->offset]) * 256, + ord($this->serveroutput->body[$this->_parsing->offset + 1])); + break; + } + self::_putDebug("I P P R E S P O N S E :\n\n"); + self::_putDebug( + sprintf("IPP version %s%s: %s", + ord($this->serveroutput->body[$this->_parsing->offset]), + ord($this->serveroutput->body[$this->_parsing->offset + 1]), + $this->serveroutput->ipp_version)); + $this->_parsing->offset+= 2; + return; + } + + protected function _parseStatusCode() + { + $status_code = + (ord($this->serveroutput->body[$this->_parsing->offset]) * 256) + + ord($this->serveroutput->body[$this->_parsing->offset + 1]); + $this->serveroutput->status = "NOT PARSED"; + $this->_parsing->offset+= 2; + if (strlen($this->serveroutput->body) < $this->_parsing->offset) + { + return false; + } + if ($status_code < 0x00FF) + { + $this->serveroutput->status = "successfull"; + } + elseif ($status_code < 0x01FF) + { + $this->serveroutput->status = "informational"; + } + elseif ($status_code < 0x02FF) + { + $this->serveroutput->status = "redirection"; + } + elseif ($status_code < 0x04FF) + { + $this->serveroutput->status = "client-error"; + } + elseif ($status_code < 0x05FF) + { + $this->serveroutput->status = "server-error"; + } + switch ($status_code) + { + case 0x0000: + $this->serveroutput->status = "successfull-ok"; + break; + + case 0x0001: + $this->serveroutput->status = "successful-ok-ignored-or-substituted-attributes"; + break; + + case 0x002: + $this->serveroutput->status = "successful-ok-conflicting-attributes"; + break; + + case 0x0400: + $this->serveroutput->status = "client-error-bad-request"; + break; + + case 0x0401: + $this->serveroutput->status = "client-error-forbidden"; + break; + + case 0x0402: + $this->serveroutput->status = "client-error-not-authenticated"; + break; + + case 0x0403: + $this->serveroutput->status = "client-error-not-authorized"; + break; + + case 0x0404: + $this->serveroutput->status = "client-error-not-possible"; + break; + + case 0x0405: + $this->serveroutput->status = "client-error-timeout"; + break; + + case 0x0406: + $this->serveroutput->status = "client-error-not-found"; + break; + + case 0x0407: + $this->serveroutput->status = "client-error-gone"; + break; + + case 0x0408: + $this->serveroutput->status = "client-error-request-entity-too-large"; + break; + + case 0x0409: + $this->serveroutput->status = "client-error-request-value-too-long"; + break; + + case 0x040A: + $this->serveroutput->status = "client-error-document-format-not-supported"; + break; + + case 0x040B: + $this->serveroutput->status = "client-error-attributes-or-values-not-supported"; + break; + + case 0x040C: + $this->serveroutput->status = "client-error-uri-scheme-not-supported"; + break; + + case 0x040D: + $this->serveroutput->status = "client-error-charset-not-supported"; + break; + + case 0x040E: + $this->serveroutput->status = "client-error-conflicting-attributes"; + break; + + case 0x040F: + $this->serveroutput->status = "client-error-compression-not-supported"; + break; + + case 0x0410: + $this->serveroutput->status = "client-error-compression-error"; + break; + + case 0x0411: + $this->serveroutput->status = "client-error-document-format-error"; + break; + + case 0x0412: + $this->serveroutput->status = "client-error-document-access-error"; + break; + + case 0x0413: // RFC3380 + $this->serveroutput->status = "client-error-attributes-not-settable"; + break; + + case 0x0500: + $this->serveroutput->status = "server-error-internal-error"; + break; + + case 0x0501: + $this->serveroutput->status = "server-error-operation-not-supported"; + break; + + case 0x0502: + $this->serveroutput->status = "server-error-service-unavailable"; + break; + + case 0x0503: + $this->serveroutput->status = "server-error-version-not-supported"; + break; + + case 0x0504: + $this->serveroutput->status = "server-error-device-error"; + break; + + case 0x0505: + $this->serveroutput->status = "server-error-temporary-error"; + break; + + case 0x0506: + $this->serveroutput->status = "server-error-not-accepting-jobs"; + break; + + case 0x0507: + $this->serveroutput->status = "server-error-busy"; + break; + + case 0x0508: + $this->serveroutput->status = "server-error-job-canceled"; + break; + + case 0x0509: + $this->serveroutput->status = "server-error-multiple-document-jobs-not-supported"; + break; + + default: + break; + } + self::_putDebug( + sprintf( + "status-code: %s%s: %s ", + $this->serveroutput->body[$this->_parsing->offset], + $this->serveroutput->body[$this->_parsing->offset + 1], + $this->serveroutput->status), + 4); + return; + } + + protected function _parseRequestID() + { + $this->serveroutput->request_id = + self::_interpretInteger( + substr($this->serveroutput->body, $this->_parsing->offset, 4) + ); + self::_putDebug("request-id " . $this->serveroutput->request_id, 2); + $this->_parsing->offset+= 4; + return; + } + + protected function _interpretInteger($value) + { + // they are _signed_ integers + $value_parsed = 0; + for ($i = strlen($value); $i > 0; $i --) + { + $value_parsed += + ( + (1 << (($i - 1) * 8)) + * + ord($value[strlen($value) - $i]) + ); + } + if ($value_parsed >= 2147483648) + { + $value_parsed -= 4294967296; + } + return $value_parsed; + } + + protected function _parseResponse() + { + } + + // + // REQUEST BUILDING + // + protected function _stringJob() + { + if (!isset($this->setup->charset)) { + self::setCharset(); + } + if (!isset($this->setup->datatype)) { + self::setBinary(); + } + if (!isset($this->setup->uri)) + { + $this->getPrinters(); + unset($this->jobs[count($this->jobs) - 1]); + unset($this->jobs_uri[count($this->jobs_uri) - 1]); + unset($this->status[count($this->status) - 1]); + if (array_key_exists(0, $this->available_printers)) + { + self::setPrinterURI($this->available_printers[0]); + } + else + { + trigger_error( + _("_stringJob: Printer URI is not set: die"), + E_USER_WARNING); + self::_putDebug(_("_stringJob: Printer URI is not set: die") , 4); + self::_errorLog(" Printer URI is not set, die", 2); + return FALSE; + } + } + if (!isset($this->setup->copies)) { + self::setCopies(1); + } + if (!isset($this->setup->language)) { + self::setLanguage('en_us'); + } + if (!isset($this->setup->mime_media_type)) { + self::setMimeMediaType(); + } + if (!isset($this->setup->jobname)) { + self::setJobName(); + } + unset($this->setup->jobname); + if (!isset($this->meta->username)) { + self::setUserName(); + } + if (!isset($this->meta->fidelity)) { + $this->meta->fidelity = ''; + } + if (!isset($this->meta->document_name)) { + $this->meta->document_name = ''; + } + if (!isset($this->meta->sides)) { + $this->meta->sides = ''; + } + if (!isset($this->meta->page_ranges)) { + $this->meta->page_ranges = ''; + } + $jobattributes = ''; + $operationattributes = ''; + $printerattributes = ''; + $this->_buildValues($operationattributes, $jobattributes, $printerattributes); + self::_setOperationId(); + if (!isset($this->error_generation->request_body_malformed)) + { + $this->error_generation->request_body_malformed = ""; + } + $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number + . chr(0x00) . chr(0x02) // Print-Job | operation-id + . $this->meta->operation_id // request-id + . chr(0x01) // start operation-attributes | operation-attributes-tag + . $this->meta->charset + . $this->meta->language + . $this->meta->printer_uri + . $this->meta->username + . $this->meta->jobname + . $this->meta->fidelity + . $this->meta->document_name + . $this->meta->mime_media_type + . $operationattributes; + if ($this->meta->copies || $this->meta->sides || $this->meta->page_ranges || !empty($jobattributes)) + { + $this->stringjob .= + chr(0x02) // start job-attributes | job-attributes-tag + . $this->meta->copies + . $this->meta->sides + . $this->meta->page_ranges + . $jobattributes; + } + $this->stringjob.= chr(0x03); // end-of-attributes | end-of-attributes-tag + self::_putDebug( + sprintf(_("String sent to the server is: %s"), + $this->stringjob) + ); + return TRUE; + } + + protected function _buildValues(&$operationattributes, &$jobattributes, &$printerattributes) + { + $operationattributes = ''; + foreach($this->operation_tags as $key => $values) + { + $item = 0; + if (array_key_exists('value', $values)) + { + foreach($values['value'] as $item_value) + { + if ($item == 0) + { + $operationattributes .= + $values['systag'] + . self::_giveMeStringLength($key) + . $key + . self::_giveMeStringLength($item_value) + . $item_value; + } + else + { + $operationattributes .= + $values['systag'] + . self::_giveMeStringLength('') + . self::_giveMeStringLength($item_value) + . $item_value; + } + $item++; + } + } + } + $jobattributes = ''; + foreach($this->job_tags as $key => $values) + { + $item = 0; + if (array_key_exists('value', $values)) + { + foreach($values['value'] as $item_value) + { + if ($item == 0) + { + $jobattributes .= + $values['systag'] + . self::_giveMeStringLength($key) + . $key + . self::_giveMeStringLength($item_value) + . $item_value; + } + else + { + $jobattributes .= + $values['systag'] + . self::_giveMeStringLength('') + . self::_giveMeStringLength($item_value) + . $item_value; + } + $item++; + } + } + } + $printerattributes = ''; + foreach($this->printer_tags as $key => $values) + { + $item = 0; + if (array_key_exists('value', $values)) + { + foreach($values['value'] as $item_value) + { + if ($item == 0) + { + $printerattributes .= + $values['systag'] + . self::_giveMeStringLength($key) + . $key + . self::_giveMeStringLength($item_value) + . $item_value; + } + else + { + $printerattributes .= + $values['systag'] + . self::_giveMeStringLength('') + . self::_giveMeStringLength($item_value) + . $item_value; + } + $item++; + } + } + } + reset($this->job_tags); + reset($this->operation_tags); + reset($this->printer_tags); + return true; + } + + protected function _giveMeStringLength($string) + { + $length = strlen($string); + if ($length > ((0xFF << 8) + 0xFF) ) + { + $errmsg = sprintf ( + _('max string length for an ipp meta-information = %d, while here %d'), + ((0xFF << 8) + 0xFF), $length); + + if ($this->with_exceptions) + { + throw new ippException($errmsg); + } + else + { + trigger_error ($errmsg, E_USER_ERROR); + } + } + $int1 = $length & 0xFF; + $length -= $int1; + $length = $length >> 8; + $int2 = $length & 0xFF; + return chr($int2) . chr($int1); + } + + protected function _enumBuild($tag, $value) + { + switch ($tag) + { + case "orientation-requested": + switch ($value) + { + case 'portrait': + $value = chr(3); + break; + + case 'landscape': + $value = chr(4); + break; + + case 'reverse-landscape': + $value = chr(5); + break; + + case 'reverse-portrait': + $value = chr(6); + break; + } + break; + + case "print-quality": + switch ($value) + { + case 'draft': + $value = chr(3); + break; + + case 'normal': + $value = chr(4); + break; + + case 'high': + $value = chr(5); + break; + } + break; + + case "finishing": + switch ($value) + { + case 'none': + $value = chr(3); + break; + + case 'staple': + $value = chr(4); + break; + + case 'punch': + $value = chr(5); + break; + + case 'cover': + $value = chr(6); + break; + + case 'bind': + $value = chr(7); + break; + + case 'saddle-stitch': + $value = chr(8); + break; + + case 'edge-stitch': + $value = chr(9); + break; + + case 'staple-top-left': + $value = chr(20); + break; + + case 'staple-bottom-left': + $value = chr(21); + break; + + case 'staple-top-right': + $value = chr(22); + break; + + case 'staple-bottom-right': + $value = chr(23); + break; + + case 'edge-stitch-left': + $value = chr(24); + break; + + case 'edge-stitch-top': + $value = chr(25); + break; + + case 'edge-stitch-right': + $value = chr(26); + break; + + case 'edge-stitch-bottom': + $value = chr(27); + break; + + case 'staple-dual-left': + $value = chr(28); + break; + + case 'staple-dual-top': + $value = chr(29); + break; + + case 'staple-dual-right': + $value = chr(30); + break; + + case 'staple-dual-bottom': + $value = chr(31); + break; + } + break; + } + $prepend = ''; + while ((strlen($value) + strlen($prepend)) < 4) + { + $prepend .= chr(0); + } + return $prepend . $value; + } + + protected function _integerBuild($value) + { + if ($value >= 2147483647 || $value < - 2147483648) + { + trigger_error( + _("Values must be between -2147483648 and 2147483647: assuming '0'") , E_USER_WARNING); + return chr(0x00) . chr(0x00) . chr(0x00) . chr(0x00); + } + $initial_value = $value; + $int1 = $value & 0xFF; + $value -= $int1; + $value = $value >> 8; + $int2 = $value & 0xFF; + $value-= $int2; + $value = $value >> 8; + $int3 = $value & 0xFF; + $value-= $int3; + $value = $value >> 8; + $int4 = $value & 0xFF; //64bits + if ($initial_value < 0) { + $int4 = chr($int4) | chr(0x80); + } + else { + $int4 = chr($int4); + } + $value = $int4 . chr($int3) . chr($int2) . chr($int1); + return $value; + } + + protected function _rangeOfIntegerBuild($integers) + { + #$integers = split(":", $integers); + $integers = preg_split("#:#", $integers); + for ($i = 0; $i < 2; $i++) { + $outvalue[$i] = self::_integerBuild($integers[$i]); + } + return $outvalue[0] . $outvalue[1]; + } + + protected function _setJobAttribute($attribute, $value) + { + //used by setAttribute + $tag_type = $this->job_tags[$attribute]['tag']; + switch ($tag_type) + { + case 'integer': + $this->job_tags[$attribute]['value'][] = self::_integerBuild($value); + break; + + case 'boolean': + case 'nameWithoutLanguage': + case 'nameWithLanguage': + case 'textWithoutLanguage': + case 'textWithLanguage': + case 'keyword': + case 'naturalLanguage': + $this->job_tags[$attribute]['value'][] = $value; + break; + + case 'enum': + $value = $this->_enumBuild($attribute, $value); // may be overwritten by children + $this->job_tags[$attribute]['value'][] = $value; + break; + + case 'rangeOfInteger': + // $value have to be: INT1:INT2 , eg 100:1000 + $this->job_tags[$attribute]['value'][] = self::_rangeOfIntegerBuild($value); + break; + + case 'resolution': + if (preg_match("#dpi#", $value)) { + $unit = chr(0x3); + } + if (preg_match("#dpc#", $value)) { + $unit = chr(0x4); + } + $search = array( + "#(dpi|dpc)#", + '#(x|-)#' + ); + $replace = array( + "", + ":" + ); + $value = self::_rangeOfIntegerBuild(preg_replace($search, $replace, $value)) . $unit; + $this->job_tags[$attribute]['value'][] = $value; + break; + + default: + trigger_error(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , E_USER_NOTICE); + self::_putDebug(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2); + self::_errorLog(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2); + return FALSE; + break; + } + $this->job_tags[$attribute]['systag'] = $this->tags_types[$tag_type]['tag']; + } + + protected function _setOperationAttribute($attribute, $value) + { + //used by setAttribute + $tag_type = $this->operation_tags[$attribute]['tag']; + switch ($tag_type) + { + case 'integer': + $this->operation_tags[$attribute]['value'][] = self::_integerBuild($value); + break; + + case 'keyword': + case 'naturalLanguage': + $this->operation_tags[$attribute]['value'][] = $value; + break; + + default: + trigger_error(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , E_USER_NOTICE); + self::_putDebug(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2); + self::_errorLog(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2); + return FALSE; + break; + } + $this->operation_tags[$attribute]['systag'] = $this->tags_types[$tag_type]['tag']; + } + + protected function _setPrinterAttribute($attribute, $value) + { + //used by setAttribute + $tag_type = $this->printer_tags[$attribute]['tag']; + switch ($tag_type) + { + case 'integer': + $this->printer_tags[$attribute]['value'][] = self::_integerBuild($value); + break; + + case 'keyword': + case 'naturalLanguage': + $this->printer_tags[$attribute]['value'][] = $value; + break; + + default: + trigger_error(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , E_USER_NOTICE); + self::_putDebug(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2); + self::_errorLog(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2); + return FALSE; + break; + } + $this->printer_tags[$attribute]['systag'] = $this->tags_types[$tag_type]['tag']; + } + + // + // DEBUGGING + // + protected function _putDebug($string, $level = 1) + { + if ($level === false) { + return; + } + + if ($level < $this->debug_level) { + return; + } + + $this->debug[$this->debug_count] = substr($string, 0, 1024); + $this->debug_count++; + //$this->debug .= substr($string,0,1024); + + } + + // + // LOGGING + // + protected function _errorLog($string_to_log, $level) + { + if ($level > $this->log_level) { + return; + } + + $string = sprintf('%s : %s:%s user %s : %s', basename($_SERVER['PHP_SELF']) , $this->host, $this->port, $this->requesting_user, $string_to_log); + + if ($this->log_type == 0) + { + error_log($string); + return; + } + + $string = sprintf("%s %s Host %s:%s user %s : %s\n", date('M d H:i:s') , basename($_SERVER['PHP_SELF']) , $this->host, $this->port, $this->requesting_user, $string_to_log); + error_log($string, $this->log_type, $this->log_destination); + return; + } +} diff --git a/htdocs/includes/printipp/CupsPrintIPP.php b/htdocs/includes/printipp/CupsPrintIPP.php index a7e5a305da5..7808c64a722 100644 --- a/htdocs/includes/printipp/CupsPrintIPP.php +++ b/htdocs/includes/printipp/CupsPrintIPP.php @@ -1,5 +1,5 @@ jobs = array_merge($this->jobs,array("")); $this->jobs_uri = array_merge($this->jobs_uri,array("")); $this->parsed = array(); unset($this->printer_attributes); - + if (!isset($this->setup->charset)) - self::setCharset('us-ascii'); - + { + self::setCharset(); + } + if (!isset($this->setup->language)) + { self::setLanguage('en'); - + } + self::_setOperationId(); - + for($i = 0 ; $i < count($attributes) ; $i++) + { if ($i == 0) + { $this->meta->attributes = chr(0x44) // Keyword . self::_giveMeStringLength('requested-attributes') . 'requested-attributes' . self::_giveMeStringLength($attributes[0]) . $attributes[0]; + } else + { $this->meta->attributes .= chr(0x44) // Keyword . chr(0x0).chr(0x0) // zero-length name . self::_giveMeStringLength($attributes[$i]) . $attributes[$i]; - - $this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1 + } + } + + $this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1 . chr(0x40). chr(0x01) // operation: cups vendor extension: get defaults . $this->meta->operation_id // request-id . chr(0x01) // start operation-attributes | operation-attributes-tag @@ -97,69 +103,83 @@ class CupsPrintIPP extends ExtendedPrintIPP { . $this->meta->language . $this->meta->attributes . chr(0x03); // end operations attribute - + $this->output = $this->stringjob; - + self::_putDebug("Request: ".$this->output); - + $post_values = array( "Content-Type" => "application/ipp", "Data" => $this->output); - - if (self::_sendHttp ($post_values,'/')) { - + + if (self::_sendHttp ($post_values,'/')) + { + if(self::_parseServerOutput()) + { self::_parsePrinterAttributes(); } - + } + $this->attributes = &$this->printer_attributes; - - if (isset($this->printer_attributes->printer_type)) { + + if (isset($this->printer_attributes->printer_type)) + { $printer_type = $this->printer_attributes->printer_type->_value0; $table = self::_interpretPrinterType($printer_type); - - for($i = 0 ; $i < count($table) ; $i++ ) { + + for($i = 0 ; $i < count($table) ; $i++ ) + { $index = '_value'.$i; $this->printer_attributes->printer_type->$index = $table[$i]; } - } - if (isset($this->serveroutput) && isset($this->serveroutput->status)) { - + if (isset($this->serveroutput) && isset($this->serveroutput->status)) + { + $this->status = array_merge($this->status,array($this->serveroutput->status)); if ($this->serveroutput->status == "successfull-ok") + { self::_errorLog("getting defaults: ".$this->serveroutput->status,3); + } else + { self::_errorLog("getting defaults: ".$this->serveroutput->status,1); - - return $this->serveroutput->status; - - } else { + } + + return $this->serveroutput->status; + } + else + { $this->status = array_merge($this->status,array("OPERATION FAILED")); self::_errorLog("getting defaults : OPERATION FAILED",1); } - return false; + return false; } - // }}} - - // {{{ cupsAcceptJobs ($printer_uri) - public function cupsAcceptJobs($printer_uri) { + + + public function cupsAcceptJobs($printer_uri) + { //The CUPS-Get-Default operation returns the default printer URI and attributes - + $this->jobs = array_merge($this->jobs,array("")); $this->jobs_uri = array_merge($this->jobs_uri,array("")); $this->parsed = array(); unset($this->printer_attributes); - + if (!isset($this->setup->charset)) - self::setCharset('us-ascii'); - + { + self::setCharset(); + } + if (!isset($this->setup->language)) + { self::setLanguage('en'); - + } + self::_setOperationId(); - - $this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1 + + $this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1 . chr(0x40). chr(0x08) // operation: cups vendor extension: Accept-Jobs . $this->meta->operation_id // request-id . chr(0x01) // start operation-attributes | operation-attributes-tag @@ -171,65 +191,80 @@ class CupsPrintIPP extends ExtendedPrintIPP { . self::_giveMeStringLength($printer_uri) . $printer_uri . chr(0x03); // end operations attribute - + $this->output = $this->stringjob; - + self::_putDebug("Request: ".$this->output); - + $post_values = array( "Content-Type" => "application/ipp", "Data" => $this->output); - - if (self::_sendHttp ($post_values,'/admin/')) { - + + if (self::_sendHttp ($post_values,'/admin/')) + { + if(self::_parseServerOutput()) + { self::_parseAttributes(); } - - if (isset($this->serveroutput) && isset($this->serveroutput->status)) { - + } + + if (isset($this->serveroutput) && isset($this->serveroutput->status)) + { + $this->status = array_merge($this->status,array($this->serveroutput->status)); if ($this->serveroutput->status == "successfull-ok") + { self::_errorLog("getting defaults: ".$this->serveroutput->status,3); + } else + { self::_errorLog("getting defaults: ".$this->serveroutput->status,1); - - return $this->serveroutput->status; - - } else { + } + + return $this->serveroutput->status; + } + else + { $this->status = array_merge($this->status,array("OPERATION FAILED")); self::_errorLog("getting defaults : OPERATION FAILED",1); } - return false; + return false; } - // }}} - // {{{ cupsRejectJobs ($printer_uri,$printer_state_message=false) - public function cupsRejectJobs($printer_uri,$printer_state_message) { + + public function cupsRejectJobs($printer_uri,$printer_state_message) + { //The CUPS-Get-Default operation returns the default printer URI and attributes - + $this->jobs = array_merge($this->jobs,array("")); $this->jobs_uri = array_merge($this->jobs_uri,array("")); $this->parsed = array(); unset($this->attributes); - + if (!isset($this->setup->charset)) - self::setCharset('us-ascii'); - + { + self::setCharset(); + } + if (!isset($this->setup->language)) + { self::setLanguage('en'); - + } + self::_setOperationId(); - + $message = ""; if ($printer_state_message) + { $message = chr(0x04) // start printer-attributes . chr(0x41) // textWithoutLanguage . self::_giveMeStringLength("printer-state-message") . "printer-state-message" . self::_giveMeStringLength($printer_state_message) . $printer_state_message; + } - $this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1 + $this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1 . chr(0x40). chr(0x09) // operation: cups vendor extension: Reject-Jobs . $this->meta->operation_id // request-id . chr(0x01) // start operation-attributes | operation-attributes-tag @@ -242,89 +277,111 @@ class CupsPrintIPP extends ExtendedPrintIPP { . $printer_uri . $message . chr(0x03); // end operations attribute - + $this->output = $this->stringjob; - + self::_putDebug("Request: ".$this->output); - + $post_values = array( "Content-Type" => "application/ipp", "Data" => $this->output); - - if (self::_sendHttp ($post_values,'/admin/')) { - + + if (self::_sendHttp ($post_values,'/admin/')) + { + if(self::_parseServerOutput()) + { self::_parseAttributes(); } - - if (isset($this->serveroutput) && isset($this->serveroutput->status)) { - + } + + if (isset($this->serveroutput) && isset($this->serveroutput->status)) + { + $this->status = array_merge($this->status,array($this->serveroutput->status)); if ($this->serveroutput->status == "successfull-ok") + { self::_errorLog("getting defaults: ".$this->serveroutput->status,3); + } else + { self::_errorLog("getting defaults: ".$this->serveroutput->status,1); - - return $this->serveroutput->status; - - } else { + } + + return $this->serveroutput->status; + } + else + { $this->status = array_merge($this->status,array("OPERATION FAILED")); self::_errorLog("getting defaults : OPERATION FAILED",1); - } - return false; + } + return false; } - // }}} - // {{{ getPrinters() - public function getPrinters($printer_location=false,$printer_info=false,$attributes=array()) { - + + public function getPrinters($printer_location=false,$printer_info=false,$attributes=array()) + { if (count($attributes) == 0) - true; - $attributes=array('printer-uri-supported','printer-location','printer-info','printer-type','color-supported'); + { + true; + } + $attributes=array('printer-uri-supported', 'printer-location', 'printer-info', 'printer-type', 'color-supported', 'printer-name'); $this->jobs = array_merge($this->jobs,array("")); $this->jobs_uri = array_merge($this->jobs_uri,array("")); - + unset ($this->printers_attributes); - + if (!isset($this->setup->charset)) - self::setCharset('us-ascii'); - + { + self::setCharset(); + } + if (!isset($this->setup->language)) + { self::setLanguage('en-us'); - + } + self::_setOperationId(); - + $this->meta->attributes=''; - + if ($printer_location) + { $this->meta->attributes .= chr(0x41) // textWithoutLanguage . self::_giveMeStringLength('printer-location') . 'printer-location' . self::_giveMeStringLength($printer_location) . $printer_location; - - + } + if ($printer_info) + { $this->meta->attributes .= chr(0x41) // textWithoutLanguage . self::_giveMeStringLength('printer-info') . 'printer-info' . self::_giveMeStringLength($printer_info) . $printer_info; - + } + for($i = 0 ; $i < count($attributes) ; $i++) + { if ($i == 0) + { $this->meta->attributes .= chr(0x44) // Keyword . self::_giveMeStringLength('requested-attributes') . 'requested-attributes' . self::_giveMeStringLength($attributes[0]) . $attributes[0]; + } else + { $this->meta->attributes .= chr(0x44) // Keyword . chr(0x0).chr(0x0) // zero-length name . self::_giveMeStringLength($attributes[$i]) . $attributes[$i]; + } + } - - $this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1 + $this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1 . chr(0x40). chr(0x02) // operation: cups vendor extension: get printers . $this->meta->operation_id // request-id . chr(0x01) // start operation-attributes | operation-attributes-tag @@ -332,78 +389,89 @@ class CupsPrintIPP extends ExtendedPrintIPP { . $this->meta->language . $this->meta->attributes . chr(0x03); // end operations attribute - + $this->output = $this->stringjob; - + $post_values = array( "Content-Type" => "application/ipp", "Data" => $this->output); - - if (self::_sendHttp ($post_values,'/')) { - - if(self::_parseServerOutput()) - $this->_getAvailablePrinters(); + if (self::_sendHttp ($post_values,'/')) + { + + if(self::_parseServerOutput()) + { + $this->_getAvailablePrinters(); } - - if (isset($this->serveroutput) && isset($this->serveroutput->status)) { - + } + + if (isset($this->serveroutput) && isset($this->serveroutput->status)) + { + $this->status = array_merge($this->status,array($this->serveroutput->status)); if ($this->serveroutput->status == "successfull-ok") + { self::_errorLog("getting printers: ".$this->serveroutput->status,3); + } else + { self::_errorLog("getting printers: ".$this->serveroutput->status,1); - return $this->serveroutput->status; - - } else { + } + return $this->serveroutput->status; + } + else + { $this->status = array_merge($this->status,array("OPERATION FAILED")); self::_errorLog("getting printers : OPERATION FAILED",1); - } - return false; + } + return false; } - // }}} - // {{{ cupsGetPrinters () - public function cupsGetPrinters () { - // alias for getPrinters(); + + public function cupsGetPrinters () + { + // alias for getPrinters(); self::getPrinters(); } - // }}} - // {{{ getPrinterAttributes() - public function getPrinterAttributes() { - // complete informations from parent with Cups-specific stuff - + + public function getPrinterAttributes() + { + // complete informations from parent with Cups-specific stuff + if(!$result = parent::getPrinterAttributes()) + { return FALSE; + } if(!isset($this->printer_attributes)) + { return FALSE; - - if (isset ($this->printer_attributes->printer_type)) { + } + + if (isset ($this->printer_attributes->printer_type)) + { $printer_type = $this->printer_attributes->printer_type->_value0; $table = self::_interpretPrinterType($printer_type); - - for($i = 0 ; $i < count($table) ; $i++ ) { + + for($i = 0 ; $i < count($table) ; $i++ ) + { $index = '_value'.$i; $this->printer_attributes->printer_type->$index = $table[$i]; - } } + } - return $result; + return $result; } - // }}} // // SETUP // - - // {{{ _initTags () - protected function _initTags () { - + protected function _initTags () + { // override parent with specific cups attributes - - $operation_tags = array (); + + $operation_tags = array (); $this->operation_tags = array_merge ($this->operation_tags, $operation_tags); - + $job_tags = array ( "job-billing" => array("tag" => "textWithoutLanguage"), "blackplot" => array("tag" => "boolean"), "brightness" => array("tag" => "integer"), @@ -430,25 +498,23 @@ class CupsPrintIPP extends ExtendedPrintIPP { "saturation" => array("tag" => "integer"), "scaling" => array("tag" => "integer"), "wrap" => array("tag","boolean"), - + ); $this->job_tags = array_merge ($this->job_tags, $job_tags); } - // }}} -// -// REQUEST BUILDING -// - - // {{{ _enumBuild ($tag,$value) - protected function _enumBuild ($tag,$value) { - + // + // REQUEST BUILDING + // + protected function _enumBuild ($tag,$value) + { $value_built = parent::_enumBuild($tag,$value); - - switch ($tag) { - case "cpi": - switch ($value) { + switch ($tag) + { + case "cpi": + switch ($value) + { case '10': $value_built = chr(10); break; @@ -463,7 +529,8 @@ class CupsPrintIPP extends ExtendedPrintIPP { } break; case "lpi": - switch ($value) { + switch ($value) + { case '6': $value_built = chr(6); break; @@ -479,60 +546,66 @@ class CupsPrintIPP extends ExtendedPrintIPP { $prepend = ''; while ((strlen($value_built) + strlen($prepend)) < 4) $prepend .= chr(0); - return $prepend.$value_built; + return $prepend.$value_built; } - // }}} - -// -// RESPONSE PARSING -// - // {{{ _getAvailablePrinters () - private function _getAvailablePrinters () { - + // + // RESPONSE PARSING + // + private function _getAvailablePrinters () + { $this->available_printers = array(); + $this->printer_map = array(); $k = 0; - $this->printers_attributes = new stdClass(); + $this->printers_attributes = new \stdClass(); for ($i = 0 ; (array_key_exists($i,$this->serveroutput->response)) ; $i ++) - if (($this->serveroutput->response[$i]['attributes']) == "printer-attributes") { + { + if (($this->serveroutput->response[$i]['attributes']) == "printer-attributes") + { $phpname = "_printer".$k; - $this->printers_attributes->$phpname = new stdClass(); - for ($j = 0 ; array_key_exists($j,$this->serveroutput->response[$i]) ; $j++) { - + $this->printers_attributes->$phpname = new \stdClass(); + for ($j = 0 ; array_key_exists($j,$this->serveroutput->response[$i]) ; $j++) + { + $value = $this->serveroutput->response[$i][$j]['value']; $name = str_replace("-","_",$this->serveroutput->response[$i][$j]['name']); - - switch ($name) { + + switch ($name) + { case "printer_uri_supported": $this->available_printers = array_merge($this->available_printers,array($value)); break; case "printer_type": $table = self::_interpretPrinterType($value); - $this->printers_attributes->$phpname->$name = new stdClass(); - - for($l = 0 ; $l < count($table) ; $l++ ) { + $this->printers_attributes->$phpname->$name = new \stdClass(); + + for($l = 0 ; $l < count($table) ; $l++ ) + { $index = '_value'.$l; $this->printers_attributes->$phpname->$name->$index = $table[$l]; } - + break; case '': break; + case 'printer_name': + $this->printer_map[$value] = $k; + break; default: $this->printers_attributes->$phpname->$name = $value; break; - } - - } - $k ++; + } } + $k ++; + } + } } - // }}} - - // {{{ _getEnumVendorExtensions - protected function _getEnumVendorExtensions ($value_parsed) { - switch ($value_parsed) { + + protected function _getEnumVendorExtensions ($value_parsed) + { + switch ($value_parsed) + { case 0x4002: $value = 'Get-Availables-Printers'; break; @@ -541,110 +614,152 @@ class CupsPrintIPP extends ExtendedPrintIPP { break; } - if (isset($value)) - return ($value); - - return sprintf('Unknown: 0x%x',$value_parsed); - } - // }}} + if (isset($value)) + { + return ($value); + } - // {{{ _interpretPrinterType($type) - private function _interpretPrinterType($value) { + return sprintf('Unknown: 0x%x',$value_parsed); + } + + + private function _interpretPrinterType($value) + { $value_parsed = 0; for ($i = strlen($value) ; $i > 0 ; $i --) + { $value_parsed += pow(256,($i - 1)) * ord($value[strlen($value) - $i]); - + } + $type[0] = $type[1] = $type[2] = $type[3] = $type[4] = $type[5] = ''; $type[6] = $type[7] = $type[8] = $type[9] = $type[10] = ''; $type[11] = $type[12] = $type[13] = $type[14] = $type[15] = ''; $type[16] = $type[17] = $type[18] = $type[19] = ''; - - if ($value_parsed %2 == 1) { + + if ($value_parsed %2 == 1) + { $type[0] = 'printer-class'; $value_parsed -= 1; - } - if ($value_parsed %4 == 2 ) { + } + + if ($value_parsed %4 == 2 ) + { $type[1] = 'remote-destination'; $value_parsed -= 2; - } - if ($value_parsed %8 == 4 ) { + } + + if ($value_parsed %8 == 4 ) + { $type[2] = 'print-black'; $value_parsed -= 4; - } - if ($value_parsed %16 == 8 ) { + } + + if ($value_parsed %16 == 8 ) + { $type[3] = 'print-color'; $value_parsed -= 8; - } - if ($value_parsed %32 == 16) { + } + + if ($value_parsed %32 == 16) + { $type[4] = 'hardware-print-on-both-sides'; $value_parsed -= 16; - } - if ($value_parsed %64 == 32) { + } + + if ($value_parsed %64 == 32) + { $type[5] = 'hardware-staple-output'; $value_parsed -= 32; - } - if ($value_parsed %128 == 64) { + } + + if ($value_parsed %128 == 64) + { $type[6] = 'hardware-fast-copies'; $value_parsed -= 64; - } - if ($value_parsed %256 == 128) { + } + + if ($value_parsed %256 == 128) + { $type[7] = 'hardware-fast-copy-collation'; $value_parsed -= 128; - } - if ($value_parsed %512 == 256) { + } + + if ($value_parsed %512 == 256) + { $type[8] = 'punch-output'; $value_parsed -= 256; - } - if ($value_parsed %1024 == 512) { + } + + if ($value_parsed %1024 == 512) + { $type[9] = 'cover-output'; $value_parsed -= 512; - } - if ($value_parsed %2048 == 1024) { + } + + if ($value_parsed %2048 == 1024) + { $type[10] = 'bind-output'; $value_parsed -= 1024; - } - if ($value_parsed %4096 == 2048) { + } + + if ($value_parsed %4096 == 2048) + { $type[11] = 'sort-output'; $value_parsed -= 2048; - } - if ($value_parsed %8192 == 4096) { + } + + if ($value_parsed %8192 == 4096) + { $type[12] = 'handle-media-up-to-US-Legal-A4'; $value_parsed -= 4096; - } - if ($value_parsed %16384 == 8192) { + } + + if ($value_parsed %16384 == 8192) + { $type[13] = 'handle-media-between-US-Legal-A4-and-ISO_C-A2'; $value_parsed -= 8192; - } - if ($value_parsed %32768 == 16384) { + } + + if ($value_parsed %32768 == 16384) + { $type[14] = 'handle-media-larger-than-ISO_C-A2'; $value_parsed -= 16384; - } - if ($value_parsed %65536 == 32768) { + } + + if ($value_parsed %65536 == 32768) + { $type[15] = 'handle-user-defined-media-sizes'; $value_parsed -= 32768; - } - if ($value_parsed %131072 == 65536) { + } + + if ($value_parsed %131072 == 65536) + { $type[16] = 'implicit-server-generated-class'; $value_parsed -= 65536; - } - if ($value_parsed %262144 == 131072) { + } + + if ($value_parsed %262144 == 131072) + { $type[17] = 'network-default-printer'; $value_parsed -= 131072; - } - if ($value_parsed %524288 == 262144) { + } + + if ($value_parsed %524288 == 262144) + { $type[18] = 'fax-device'; $value_parsed -= 262144; - } - return $type; - } - // }}} + } - // {{{ _interpretEnum() - protected function _interpretEnum($attribute_name,$value) { - + return $type; + } + + + protected function _interpretEnum($attribute_name,$value) + { $value_parsed = self::_interpretInteger($value); - - switch ($attribute_name) { + + switch ($attribute_name) + { case 'cpi': case 'lpi': $value = $value_parsed; @@ -652,20 +767,8 @@ class CupsPrintIPP extends ExtendedPrintIPP { default: $value = parent::_interpretEnum($attribute_name,$value); break; - } - - - return $value; - } - // }}} - -}; + } -/* - * Local variables: - * mode: php - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ -?> + return $value; + } +} \ No newline at end of file diff --git a/htdocs/includes/printipp/ExtendedPrintIPP.php b/htdocs/includes/printipp/ExtendedPrintIPP.php index e736f4bd972..3effacb828f 100644 --- a/htdocs/includes/printipp/ExtendedPrintIPP.php +++ b/htdocs/includes/printipp/ExtendedPrintIPP.php @@ -1,5 +1,5 @@ document_uri = $uri; $this->setup->uri = 1; } - + if(!$this->_stringUri()) + { return FALSE; - + } + $this->output = $this->stringjob; - + $post_values = array( "Content-Type" => "application/ipp", "Data" => $this->output); - - - if (self::_sendHttp ($post_values,$this->paths['printers'])) { - - if(self::_parseServerOutput()) { + + if (self::_sendHttp ($post_values,$this->paths['printers'])) + { + if(self::_parseServerOutput()) + { $this->_parseJobAttributes(); $this->_getJobId(); //$this->_getPrinterUri(); $this->_getJobUri(); } } - + $this->attributes = &$this->job_attributes; - - if (isset($this->serveroutput) && isset($this->serveroutput->status)) { - + + if (isset($this->serveroutput) && isset($this->serveroutput->status)) + { $this->status = array_merge($this->status,array($this->serveroutput->status)); if ($this->serveroutput->status == "successfull-ok") + { self::_errorLog(sprintf("printing uri %s, job %s: ",$uri,$this->last_job) .$this->serveroutput->status,3); - else { + } + else + { $this->jobs = array_merge($this->jobs,array("")); $this->jobs_uri = array_merge($this->jobs_uri,array("")); self::_errorLog(sprintf("printing uri %s: ",$uri,$this->last_job) .$this->serveroutput->status,1); - } - return $this->serveroutput->status; } - + return $this->serveroutput->status; + } + $this->status = array_merge($this->status,array("OPERATION FAILED")); self::_errorLog("printing uri $uri : OPERATION FAILED",1); - - return false; - } - // }}} - // {{{ purgeJobs() - public function purgeJobs() { - + return false; + } + + + public function purgeJobs() + { $this->jobs = array_merge($this->jobs,array("")); $this->jobs_uri = array_merge($this->jobs_uri,array("")); self::_setOperationId(); $this->parsed = array(); unset($this->printer_attributes); - - if (!isset($this->setup->uri)) { + + if (!isset($this->setup->uri)) + { $this->getPrinters(); unset($this->jobs[count($this->jobs) - 1]); unset($this->jobs_uri[count($this->jobs_uri) - 1]); unset($this->status[count($this->status) - 1]); - + if (array_key_exists(0,$this->available_printers)) + { self::setPrinterURI($this->available_printers[0]); - else { + } + else + { trigger_error(_("purgeJobs: Printer URI is not set: die"),E_USER_WARNING); self::_putDebug( _("purgeJobs: Printer URI is not set: die\n")); self::_errorLog("purgeJobs: Printer URI is not set, die",2); return FALSE; } } - + if (!isset($this->setup->charset)) - self::setCharset('us-ascii'); - + { + self::setCharset(); + } + if (!isset($this->setup->language)) + { self::setLanguage('en_us'); + } if (!isset($this->meta->username)) + { self::setUserName(); - + } + $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number . chr(0x00) . chr (0x12) // purge-Jobs | operation-id . $this->meta->operation_id // request-id @@ -164,116 +169,141 @@ class ExtendedPrintIPP extends PrintIPP { . self::_giveMeStringLength(chr(0x01)) . chr(0x01) . chr(0x03); // end-of-attributes | end-of-attributes-tag - + self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob)); - + self::_putDebug(sprintf(_("purging jobs of %s\n"),$this->printer_uri)); - + $this->output = $this->stringjob; - + $post_values = array( "Content-Type"=>"application/ipp", "Data"=>$this->output); - - if (self::_sendHttp ($post_values,$this->paths['admin'])) { + + if (self::_sendHttp ($post_values,$this->paths['admin'])) + { self::_parseServerOutput(); self::_parseAttributes(); } - - if (isset($this->serveroutput) && isset($this->serveroutput->status)) { - + if (isset($this->serveroutput) && isset($this->serveroutput->status)) + { $this->status = array_merge($this->status,array($this->serveroutput->status)); - + if ($this->serveroutput->status == "successfull-ok") + { self::_errorLog(sprintf(_("purging jobs of %s: "),$this->printer_uri) .$this->serveroutput->status,3); + } else + { self::_errorLog(sprintf(_("purging jobs of %s: "),$this->printer_uri) .$this->serveroutput->status,1); - + } + return $this->serveroutput->status; - } - + } + $this->status = array_merge($this->status,array("OPERATION FAILED")); self::_errorLog(date("Y-m-d H:i:s : ") .basename($_SERVER['PHP_SELF']) .sprintf(_("purging jobs of %s : OPERATION FAILED"), $this->printer_uri),3); - - return false; + + return false; } - // }}} - - // {{{ createJob() - public function createJob() { - - + public function createJob() + { self::_setOperationId(); $this->parsed = array(); unset($this->printer_attributes); - - if (!isset($this->setup->uri)) { + + if (!isset($this->setup->uri)) + { $this->getPrinters(); unset($this->jobs[count($this->jobs) - 1]); unset($this->jobs_uri[count($this->jobs_uri) - 1]); unset($this->status[count($this->status) - 1]); - + if (array_key_exists(0,$this->available_printers)) + { self::setPrinterURI($this->available_printers[0]); - else { + } + else + { trigger_error(_("createJob: Printer URI is not set: die"),E_USER_WARNING); self::_putDebug( _("createJob: Printer URI is not set: die\n")); self::_errorLog("createJob: Printer URI is not set, die",2); return FALSE; } } - + if (!isset($this->setup->charset)) - self::setCharset('us-ascii'); - + { + self::setCharset(); + } + if (!isset($this->setup->language)) + { self::setLanguage('en_us'); + } if (!isset($this->meta->username)) + { self::setUserName(); - + } + if (!isset($this->setup->copies)) + { self::setCopies(1); + } if (!isset($this->meta->fidelity)) + { $this->meta->fidelity = ''; + } if (!isset($this->meta->sides)) + { $this->meta->sides = ''; - + } + if (!isset($this->meta->page_ranges)) + { $this->meta->page_ranges = ''; - + } + if (!isset($this->setup->jobname)) + { if (is_readable($this->data)) + { self::setJobName(basename($this->data),true); + } else + { self::setJobName(); + } + } unset($this->setup->jobname); if (!isset($this->timeout)) + { $this->timeout = 60; - + } + $timeout = self::_integerBuild($this->timeout); - $this->meta->timeout = chr(0x21) // integer . self::_giveMeStringLength("multiple-operation-time-out") . "multiple-operation-time-out" . self::_giveMeStringLength($timeout) . $timeout; - + $jobattributes = ''; $operationattributes = ''; $printerattributes = ''; self::_buildValues($operationattributes,$jobattributes,$printerattributes); - + $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number . chr(0x00) . chr (0x05) // Create-Job | operation-id . $this->meta->operation_id // request-id @@ -292,40 +322,44 @@ class ExtendedPrintIPP extends PrintIPP { . $this->meta->page_ranges . $jobattributes . chr(0x03); // end-of-attributes | end-of-attributes-tag - + unset ($this->meta->copies,$this->meta->sides,$this->meta->page_ranges); self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob)); - + self::_putDebug(sprintf(_("creating job %s, printer %s\n"),$this->last_job,$this->printer_uri)); - + $this->output = $this->stringjob; - + $post_values = array( "Content-Type"=>"application/ipp", "Data"=>$this->output); - + if (self::_sendHttp ($post_values,$this->paths['printers'])) - if(self::_parseServerOutput()) { + { + if(self::_parseServerOutput()) + { $this->_getJobId(); $this->_getJobUri(); $this->_parseJobAttributes(); - } else { + } + else + { $this->jobs = array_merge($this->jobs,array('')); $this->jobs_uri = array_merge($this->jobs_uri,array('')); - } + } + } - - - - - if (isset($this->serveroutput) && isset($this->serveroutput->status)) { - + if (isset($this->serveroutput) && isset($this->serveroutput->status)) + { $this->status = array_merge($this->status,array($this->serveroutput->status)); - + if ($this->serveroutput->status == "successfull-ok") + { self::_errorLog(sprintf(_("Create job: job %s"),$this->last_job) .$this->serveroutput->status,3); - else { + } + else + { $this->jobs = array_merge($this->jobs,array("")); $this->jobs_uri = array_merge($this->jobs_uri,array("")); @@ -333,186 +367,207 @@ class ExtendedPrintIPP extends PrintIPP { } return $this->serveroutput->status; } - + $this->status = array_merge($this->status,array("OPERATION FAILED")); self::_errorLog(date("Y-m-d H:i:s : ") .basename($_SERVER['PHP_SELF']) .sprintf(_("Creating job on %s : OPERATION FAILED"), $this->printer_uri),3); - + $this->jobs = array_merge($this->jobs,array("")); $this->jobs_uri = array_merge($this->jobs_uri,array("")); - return false; + return false; } - // }}} - - // {{{ sendDocument($job) - public function sendDocument($job,$is_last=false){ - + public function sendDocument($job,$is_last=false) + { self::_putDebug( sprintf("*************************\nDate: %s\n*************************\n\n",date('Y-m-d H:i:s'))); if (!$this->_stringDocument($job,$is_last)) + { return FALSE; - - if (is_readable($this->data)){ + } + + if (is_readable($this->data)) + { self::_putDebug( _("sending Document\n")); - + $this->output = $this->stringjob; - + if ($this->setup->datatype == "TEXT") - $this->output .= chr(0x16); // ASCII "SYN" - - + { + $this->output .= chr(0x16); + } // ASCII "SYN" + $post_values = array( "Content-Type" => "application/ipp", "Data" => $this->output, "File" => $this->data); - + if ($this->setup->datatype == "TEXT" && !isset($this->setup->noFormFeed)) + { $post_values = array_merge($post_values,array("Filetype"=>"TEXT")); - - } else { + } + } + else + { self::_putDebug( _("sending DATA as document\n")); - + $this->output = $this->stringjob; $this->output .= $this->datahead; $this->output .= $this->data; $this->output .= $this->datatail; - + $post_values = array( "Content-Type" => "application/ipp", "Data" => $this->output); - - - } - - if (self::_sendHttp ($post_values,$this->paths['printers'])) { - - if(self::_parseServerOutput()) { + } + + if (self::_sendHttp ($post_values,$this->paths['printers'])) + { + + if(self::_parseServerOutput()) + { $this->_getJobId(); //$this->_getPrinterUri(); $this->_getJobUri(); $this->_parseJobAttributes(); - } else { + } + else + { $this->jobs = array_merge($this->jobs,array($job)); $this->jobs_uri = array_merge($this->jobs_uri,array($job)); } - } - if (isset($this->serveroutput) && isset($this->serveroutput->status)) { - + if (isset($this->serveroutput) && isset($this->serveroutput->status)) + { $this->status = array_merge($this->status,array($this->serveroutput->status)); if ($this->serveroutput->status == "successfull-ok") + { self::_errorLog(sprintf("sending document, job %s: %s",$job,$this->serveroutput->status),3); - else { + } + else + { $this->jobs = array_merge($this->jobs,array("")); $this->jobs_uri = array_merge($this->jobs_uri,array("")); self::_errorLog(sprintf("sending document, job %s: %s",$job,$this->serveroutput->status),1); - } - return $this->serveroutput->status; - } + return $this->serveroutput->status; + } $this->status = array_merge($this->status,array("OPERATION FAILED")); $this->jobs = array_merge($this->jobs,array($job)); $this->jobs_uri = array_merge($this->jobs_uri,array($job)); self::_errorLog(sprintf("sending document, job %s : OPERATION FAILED",$job),1); - - return false; + + return false; } - // }}} - // {{{ sendURI ($uri,$job,$is_last=false) - public function sendURI ($uri,$job,$is_last=false){ + public function sendURI ($uri,$job,$is_last=false) + { self::_putDebug( sprintf("*************************\nDate: %s\n*************************\n\n",date('Y-m-d H:i:s'))); if (!$this->_stringSendUri($uri,$job,$is_last)) + { return FALSE; - + } + self::_putDebug( _("sending URI $uri\n")); - + $this->output = $this->stringjob; - + $post_values = array( "Content-Type" => "application/ipp", "Data" => $this->output); - - if (self::_sendHttp ($post_values,$this->paths['printers'])) { - - if(self::_parseServerOutput()) { + + if (self::_sendHttp ($post_values,$this->paths['printers'])) + { + if(self::_parseServerOutput()) + { $this->_getJobId(); //$this->_getPrinterUri(); $this->_getJobUri(); $this->_parseJobAttributes(); - } else { + } + else + { $this->jobs = array_merge($this->jobs,array($job)); $this->jobs_uri = array_merge($this->jobs_uri,array($job)); } - } - + $this->attributes = &$this->job_attributes; - if (isset($this->serveroutput) && isset($this->serveroutput->status)) { - + if (isset($this->serveroutput) && isset($this->serveroutput->status)) + { $this->status = array_merge($this->status,array($this->serveroutput->status)); if ($this->serveroutput->status == "successfull-ok") + { self::_errorLog(sprintf("sending uri %s, job %s: %s",$uri,$job,$this->serveroutput->status),3); - else { + } + else + { $this->jobs = array_merge($this->jobs,array("")); $this->jobs_uri = array_merge($this->jobs_uri,array("")); self::_errorLog(sprintf("sending uri, job %s: %s",$uri,$job,$this->serveroutput->status),1); - } - return $this->serveroutput->status; - } + return $this->serveroutput->status; + } $this->status = array_merge($this->status,array("OPERATION FAILED")); $this->jobs = array_merge($this->jobs,array($job)); $this->jobs_uri = array_merge($this->jobs_uri,array($job)); self::_errorLog(sprintf("sending uri %s, job %s : OPERATION FAILED",$uri,$job),1); - - return false; - } - // }}} - // {{{ pausePrinter () - public function pausePrinter() { - + return false; + } + + + public function pausePrinter() + { $this->jobs = array_merge($this->jobs,array("")); $this->jobs_uri = array_merge($this->jobs_uri,array("")); self::_setOperationId(); $this->parsed = array(); unset($this->printer_attributes); - - if (!isset($this->setup->uri)) { + + if (!isset($this->setup->uri)) + { $this->getPrinters(); unset($this->jobs[count($this->jobs) - 1]); unset($this->jobs_uri[count($this->jobs_uri) - 1]); unset($this->status[count($this->status) - 1]); - + if (array_key_exists(0,$this->available_printers)) + { self::setPrinterURI($this->available_printers[0]); - else { + } + else + { trigger_error(_("pausePrinter: Printer URI is not set: die"),E_USER_WARNING); self::_putDebug( _("pausePrinter: Printer URI is not set: die\n")); self::_errorLog("pausePrinter: Printer URI is not set, die",2); return FALSE; - } } - + } + if (!isset($this->setup->charset)) - self::setCharset('us-ascii'); - + { + self::setCharset(); + } + if (!isset($this->setup->language)) + { self::setLanguage('en_us'); + } if (!isset($this->meta->username)) + { self::setUserName(); - + } + $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number . chr(0x00) . chr (0x10) // Pause-Printer | operation-id . $this->meta->operation_id // request-id @@ -527,81 +582,94 @@ class ExtendedPrintIPP extends PrintIPP { . self::_giveMeStringLength(chr(0x01)) . chr(0x01) */ . chr(0x03); // end-of-attributes | end-of-attributes-tag - + self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob)); - + self::_putDebug(sprintf(_("pause printer %s\n"),$this->printer_uri)); - + $this->output = $this->stringjob; - + $post_values = array( "Content-Type"=>"application/ipp", "Data"=>$this->output); - - if (self::_sendHttp ($post_values,$this->paths['admin'])) { + + if (self::_sendHttp ($post_values,$this->paths['admin'])) + { self::_parseServerOutput(); self::_parseAttributes(); - } + } - - if (isset($this->serveroutput) && isset($this->serveroutput->status)) { - + if (isset($this->serveroutput) && isset($this->serveroutput->status)) + { $this->status = array_merge($this->status,array($this->serveroutput->status)); - + if ($this->serveroutput->status == "successfull-ok") + { self::_errorLog(sprintf(_("Pause printer %s: "),$this->printer_uri) .$this->serveroutput->status,3); + } else + { self::_errorLog(sprintf(_("pause printer %s: "),$this->printer_uri) .$this->serveroutput->status,1); - + } + return $this->serveroutput->status; - } - + } + $this->status = array_merge($this->status,array("OPERATION FAILED")); self::_errorLog(date("Y-m-d H:i:s : ") .basename($_SERVER['PHP_SELF']) .sprintf(_("pause printer %s : OPERATION FAILED"), $this->printer_uri),3); - - return false; - } - // }}} - // {{{ resumePrinter () - public function resumePrinter() { - + return false; + } + + + public function resumePrinter() + { $this->jobs = array_merge($this->jobs,array("")); $this->jobs_uri = array_merge($this->jobs_uri,array("")); self::_setOperationId(); $this->parsed = array(); unset($this->printer_attributes); - - if (!isset($this->setup->uri)) { + + if (!isset($this->setup->uri)) + { $this->getPrinters(); unset($this->jobs[count($this->jobs) - 1]); unset($this->jobs_uri[count($this->jobs_uri) - 1]); unset($this->status[count($this->status) - 1]); - + if (array_key_exists(0,$this->available_printers)) + { self::setPrinterURI($this->available_printers[0]); - else { + } + else + { trigger_error(_("resumePrinter: Printer URI is not set: die"),E_USER_WARNING); self::_putDebug( _("resumePrinter: Printer URI is not set: die\n")); self::_errorLog(" Printer URI is not set, die",2); return FALSE; - } } - + } + if (!isset($this->setup->charset)) - self::setCharset('us-ascii'); - + { + self::setCharset(); + } + if (!isset($this->setup->language)) + { self::setLanguage('en_us'); + } if (!isset($this->meta->username)) + { self::setUserName(); - + } + $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number . chr(0x00) . chr (0x11) // suse-Printer | operation-id . $this->meta->operation_id // request-id @@ -611,82 +679,97 @@ class ExtendedPrintIPP extends PrintIPP { . $this->meta->printer_uri . $this->meta->username . chr(0x03); // end-of-attributes | end-of-attributes-tag - + self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob)); - + self::_putDebug(sprintf(_("resume printer %s\n"),$this->printer_uri)); - + $this->output = $this->stringjob; - + $post_values = array( "Content-Type"=>"application/ipp", "Data"=>$this->output); - - if (self::_sendHttp ($post_values,$this->paths['admin'])) { + + if (self::_sendHttp ($post_values,$this->paths['admin'])) + { self::_parseServerOutput(); self::_parseAttributes(); - } + } - - if (isset($this->serveroutput) && isset($this->serveroutput->status)) { - + if (isset($this->serveroutput) && isset($this->serveroutput->status)) + { $this->status = array_merge($this->status,array($this->serveroutput->status)); - + if ($this->serveroutput->status == "successfull-ok") + { self::_errorLog(sprintf(_("resume printer %s: "),$this->printer_uri) .$this->serveroutput->status,3); + } else + { self::_errorLog(sprintf(_("resume printer %s: "),$this->printer_uri) .$this->serveroutput->status,1); - + } + return $this->serveroutput->status; - } - + } + $this->status = array_merge($this->status,array("OPERATION FAILED")); self::_errorLog(date("Y-m-d H:i:s : ") .basename($_SERVER['PHP_SELF']) .sprintf(_("resume printer %s : OPERATION FAILED"), $this->printer_uri),3); - - return false; - } - // }}} - // {{{ holdJob ($job_uri) - public function holdJob ($job_uri,$until='indefinite') { - + return false; + } + + + public function holdJob ($job_uri,$until='indefinite') + { $this->jobs = array_merge($this->jobs,array("")); $this->jobs_uri = array_merge($this->jobs_uri,array(trim($job_uri))); self::_setOperationId(); $this->parsed = array(); unset($this->printer_attributes); - + if (!isset($this->setup->charset)) - self::setCharset('us-ascii'); - + { + self::setCharset(); + } + if (!isset($this->setup->language)) + { self::setLanguage('en_us'); + } if (!isset($this->meta->username)) + { self::setUserName(); - + } + if (!isset($this->meta->message)) + { $this->meta->message = ''; + } self::_setJobUri($job_uri); $until_strings = array('no-hold','day-time','evening','night','weekend','second-shift','third-shift'); if (in_array($until,$until_strings)) + { true; + } else + { $until = 'indefinite'; + } $this->meta->job_hold_until = chr(0x42) // keyword . self::_giveMeStringLength('job-hold-until') . 'job-hold-until' . self::_giveMeStringLength($until) . $until; - + $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number . chr(0x00) . chr (0x0C) // Hold-Job | operation-id . $this->meta->operation_id // request-id @@ -698,68 +781,81 @@ class ExtendedPrintIPP extends PrintIPP { . $this->meta->message . $this->meta->job_hold_until . chr(0x03); // end-of-attributes | end-of-attributes-tag - + self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob)); - + self::_putDebug(sprintf(_("hold job %s until %s\n"),$job_uri,$until)); - + $this->output = $this->stringjob; - + $post_values = array( "Content-Type"=>"application/ipp", "Data"=>$this->output); - - if (self::_sendHttp ($post_values,$this->paths['jobs'])) { + + if (self::_sendHttp ($post_values,$this->paths['jobs'])) + { self::_parseServerOutput(); self::_parseAttributes(); } - if (isset($this->serveroutput) && isset($this->serveroutput->status)) { + if (isset($this->serveroutput) && isset($this->serveroutput->status)) + { $this->status = array_merge($this->status,array($this->serveroutput->status)); if ($this->serveroutput->status == "successfull-ok") + { self::_errorLog(sprintf(_("hold job %s until %s: "),$job_uri,$until) .$this->serveroutput->status,3); + } else + { self::_errorLog(sprintf(_("hold job %s until %s: "),$job_uri,$until) .$this->serveroutput->status,1); - + } + return $this->serveroutput->status; - } - + } + $this->status = array_merge($this->status,array("OPERATION FAILED")); self::_errorLog(date("Y-m-d H:i:s : ") .basename($_SERVER['PHP_SELF']) .sprintf(_("hold job %s until %s : OPERATION FAILED"), $job_uri,$until),3); - - return false; + + return false; } - // }}} - - // {{{ releaseJob ($job_uri) - public function releaseJob ($job_uri) { + + public function releaseJob ($job_uri) + { $this->jobs = array_merge($this->jobs,array("")); $this->jobs_uri = array_merge($this->jobs_uri,array(trim($job_uri))); self::_setOperationId(); $this->parsed = array(); unset($this->printer_attributes); - + if (!isset($this->setup->charset)) - self::setCharset('us-ascii'); - + { + self::setCharset(); + } + if (!isset($this->setup->language)) + { self::setLanguage('en_us'); + } if (!isset($this->meta->username)) + { self::setUserName(); - + } + if (!isset($this->meta->message)) + { $this->meta->message = ''; + } self::_setJobUri($job_uri); - + $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number . chr(0x00) . chr (0x0D) // Hold-Job | operation-id . $this->meta->operation_id // request-id @@ -770,75 +866,85 @@ class ExtendedPrintIPP extends PrintIPP { . $this->meta->username . $this->meta->message . chr(0x03); // end-of-attributes | end-of-attributes-tag - + self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob)); - + self::_putDebug(sprintf(_("release job %s\n"),$job_uri)); - + $this->output = $this->stringjob; - + $post_values = array( "Content-Type"=>"application/ipp", "Data"=>$this->output); - - if (self::_sendHttp ($post_values,$this->paths['jobs'])) { + + if (self::_sendHttp ($post_values,$this->paths['jobs'])) + { self::_parseServerOutput(); self::_parseAttributes(); - } - if (isset($this->serveroutput) && isset($this->serveroutput->status)) { - + } + if (isset($this->serveroutput) && isset($this->serveroutput->status)) + { $this->status = array_merge($this->status,array($this->serveroutput->status)); if ($this->serveroutput->status == "successfull-ok") + { self::_errorLog(sprintf(_("release job %s: "),$job_uri) .$this->serveroutput->status,3); + } else + { self::_errorLog(sprintf(_("release job %s: "),$job_uri) .$this->serveroutput->status,1); - + } + return $this->serveroutput->status; - } - + } + $this->status = array_merge($this->status,array("OPERATION FAILED")); self::_errorLog(date("Y-m-d H:i:s : ") .basename($_SERVER['PHP_SELF']) .sprintf(_("release job %s: OPERATION FAILED"), $job_uri),3); - - return false; + + return false; } - // }}} - - // {{{ restartJob ($job_uri) - public function restartJob ($job_uri) { - + + + public function restartJob ($job_uri) + { $this->jobs = array_merge($this->jobs,array("")); $this->jobs_uri = array_merge($this->jobs_uri,array(trim($job_uri))); self::_setOperationId(); $this->parsed = array(); unset($this->printer_attributes); - + if (!isset($this->setup->charset)) - self::setCharset('us-ascii'); - + { + self::setCharset(); + } + if (!isset($this->setup->language)) + { self::setLanguage('en_us'); + } if (!isset($this->meta->username)) + { self::setUserName(); - + } + if (!isset($this->meta->message)) + { $this->meta->message = ''; + } self::_setJobUri($job_uri); - - + $jobattributes = ''; $operationattributes = ''; $printerattributes = ''; self::_buildValues ($operationattributes,$jobattributes,$printerattributes); - $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number . chr(0x00) . chr (0x0E) // Hold-Job | operation-id . $this->meta->operation_id // request-id @@ -850,92 +956,110 @@ class ExtendedPrintIPP extends PrintIPP { . $this->meta->message . $jobattributes // job-hold-until is set by setAttribute($attribute,$value) . chr(0x03); // end-of-attributes | end-of-attributes-tag - + self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob)); - + self::_putDebug(sprintf(_("release job %s\n"),$job_uri)); - + $this->output = $this->stringjob; - + $post_values = array( "Content-Type"=>"application/ipp", "Data"=>$this->output); - - if (self::_sendHttp ($post_values,$this->paths['jobs'])) { + + if (self::_sendHttp ($post_values,$this->paths['jobs'])) + { self::_parseServerOutput(); self::_parseAttributes(); - } - - if (isset($this->serveroutput) && isset($this->serveroutput->status)) { - + } + + if (isset($this->serveroutput) && isset($this->serveroutput->status)) + { $this->status = array_merge($this->status,array($this->serveroutput->status)); - + if ($this->serveroutput->status == "successfull-ok") + { self::_errorLog(sprintf(_("release job %s: "),$job_uri) .$this->serveroutput->status,3); + } else + { self::_errorLog(sprintf(_("release job %s: "),$job_uri) .$this->serveroutput->status,1); - + } + return $this->serveroutput->status; - } - + } + $this->status = array_merge($this->status,array("OPERATION FAILED")); self::_errorLog(date("Y-m-d H:i:s : ") .basename($_SERVER['PHP_SELF']) .sprintf(_("release job %s: OPERATION FAILED"), $job_uri),3); - - return false; + + return false; } - // }}} - - // {{{ setJobAttributes ($job_uri,$deleted_attributes=array()) - public function setJobAttributes ($job_uri,$deleted_attributes=array()) { - + + + public function setJobAttributes ($job_uri,$deleted_attributes=array()) + { $this->jobs = array_merge($this->jobs,array("")); $this->jobs_uri = array_merge($this->jobs_uri,array(trim($job_uri))); self::_setOperationId(); $this->parsed = array(); unset ($this->attributes); - + if (!isset($this->setup->charset)) - self::setCharset('us-ascii'); - + { + self::setCharset(); + } + if (!isset($this->setup->language)) + { self::setLanguage('en_us'); + } if (!isset($this->meta->username)) + { self::setUserName(); - - if (!isset($this->meta->message)) - $this->meta->message = ''; + } + + if (!isset($this->meta->message)) + { + $this->meta->message = ''; + } - if (!isset($this->meta->copies)) + { $this->meta->copies = ''; + } if (!isset($this->meta->sides)) + { $this->meta->sides = ''; - + } + if (!isset($this->meta->page_ranges)) + { $this->meta->page_ranges = ''; + } self::_setJobUri($job_uri); - + $operationattributes = ''; $jobattributes = ''; $printerattributes = ''; self::_buildValues ($operationattributes,$jobattributes,$printerattributes); - + $this->meta->deleted_attributes = ""; for ($i = 0 ; $i < count($deleted_attributes) ; $i++) - $this->meta->deleted_attributes .= chr(0x16) // out-of-band value - . self::_giveMeStringLength($deleted_attributes[$i]) - . $deleted_attributes[$i] - . chr(0x0).chr(0x0); // value-length = 0; - - + { + $this->meta->deleted_attributes .= chr(0x16) // out-of-band value + . self::_giveMeStringLength($deleted_attributes[$i]) + . $deleted_attributes[$i] + . chr(0x0).chr(0x0); + } // value-length = 0; + $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number . chr(0x00) . chr (0x14) // Set-Job-Attributes | operation-id . $this->meta->operation_id // request-id @@ -952,47 +1076,52 @@ class ExtendedPrintIPP extends PrintIPP { . $this->meta->page_ranges . $this->meta->deleted_attributes . chr(0x03); // end-of-attributes | end-of-attributes-tag - + self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob)); - + self::_putDebug(sprintf(_("set job attributes for job %s\n"),$job_uri)); - + $this->output = $this->stringjob; - + $post_values = array( "Content-Type"=>"application/ipp", "Data"=>$this->output); - - if (self::_sendHttp ($post_values,$this->paths['jobs'])) { + + if (self::_sendHttp ($post_values,$this->paths['jobs'])) + { self::_parseServerOutput(); self::_parseAttributes(); - } - if (isset($this->serveroutput) && isset($this->serveroutput->status)) { - + } + if (isset($this->serveroutput) && isset($this->serveroutput->status)) + { $this->status = array_merge($this->status,array($this->serveroutput->status)); - + if ($this->serveroutput->status == "successfull-ok") + { self::_errorLog(sprintf(_("set job attributes for job %s: "),$job_uri) .$this->serveroutput->status,3); + } else + { self::_errorLog(sprintf(_("set job attributes for job %s: "),$job_uri) .$this->serveroutput->status,1); + } $this->last_job = $job_uri; $this->jobs_uri[count($this->jobs_uri) - 1] = $job_uri; return $this->serveroutput->status; - } - + } + $this->status = array_merge($this->status,array("OPERATION FAILED")); self::_errorLog(date("Y-m-d H:i:s : ") .basename($_SERVER['PHP_SELF']) .sprintf(_("set job attributes for job %s: OPERATION FAILED"), $job_uri),3); - - return false; + + return false; } - // }}} - - // {{{ setPrinterAttributes () - public function setPrinterAttributes ($document_format='',$deleted_attributes=array()) { + + + public function setPrinterAttributes ($document_format='',$deleted_attributes=array()) + { /* $document_format (RFC 3380) If the client includes this attribute, the Printer MUST change the supplied attributes for the document format specified by @@ -1010,55 +1139,72 @@ class ExtendedPrintIPP extends PrintIPP { supplied attributes for all document formats, whether or not they vary by document-format. */ - + $this->jobs = array_merge($this->jobs,array("")); $this->jobs_uri = array_merge($this->jobs_uri,array("")); unset ($this->attributes); - + self::_setOperationId(); $this->parsed = array(); - + if (!isset($this->setup->charset)) - self::setCharset('us-ascii'); - + { + self::setCharset(); + } + if (!isset($this->setup->language)) + { self::setLanguage('en_us'); + } if (!isset($this->meta->username)) + { self::setUserName(); - + } + if (!isset($this->meta->message)) + { $this->meta->message = ''; - + } + if (!isset($this->meta->copies)) + { $this->meta->copies = ''; + } if (!isset($this->meta->sides)) + { $this->meta->sides = ''; - + } + if (!isset($this->meta->page_ranges)) + { $this->meta->page_ranges = ''; - + } + if ($document_format) + { $document_format = chr(0x49) // document-format tag - . self::_giveMeStringLength('document-format') - . 'document-format' // - . self::_giveMeStringLength($document_format) - . $document_format; // value + . self::_giveMeStringLength('document-format') + . 'document-format' // + . self::_giveMeStringLength($document_format) + . $document_format; + } // value $operationattributes = ''; $jobattributes = ''; $printerattributes = ''; self::_buildValues ($operationattributes,$jobattributes,$printerattributes); - + $this->meta->deleted_attributes = ""; for ($i = 0 ; $i < count($deleted_attributes) ; $i++) + { $this->meta->deleted_attributes .= chr(0x16) // out-of-band "deleted" value . self::_giveMeStringLength($deleted_attributes[$i]) . $deleted_attributes[$i] - . chr(0x0).chr(0x0); // value-length = 0; - - + . chr(0x0).chr(0x0); + } // value-length = 0; + $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number . chr(0x00) . chr (0x13) // Set-Printer-Attributes | operation-id . $this->meta->operation_id // request-id @@ -1076,144 +1222,176 @@ class ExtendedPrintIPP extends PrintIPP { . $this->meta->page_ranges . $this->meta->deleted_attributes . chr(0x03); // end-of-attributes | end-of-attributes-tag - + self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob)); - + self::_putDebug(sprintf(_("set printer attributes for job %s\n"),$this->printer_uri)); - + $this->output = $this->stringjob; - + $post_values = array( "Content-Type"=>"application/ipp", "Data"=>$this->output); - - if (self::_sendHttp ($post_values,$this->paths['printers'])) { + + if (self::_sendHttp ($post_values,$this->paths['printers'])) + { self::_parseServerOutput(); self::_parseAttributes(); - } - if (isset($this->serveroutput) && isset($this->serveroutput->status)) { - + } + if (isset($this->serveroutput) && isset($this->serveroutput->status)) + { $this->status = array_merge($this->status,array($this->serveroutput->status)); - + if ($this->serveroutput->status == "successfull-ok") + { self::_errorLog(sprintf(_("set printer attributes for printer %s: "),$this->printer_uri) .$this->serveroutput->status,3); + } else + { self::_errorLog(sprintf(_("set printer attributes for printer %s: "),$this->printer_uri) .$this->serveroutput->status,1); - + } + return $this->serveroutput->status; - } - + } + $this->status = array_merge($this->status,array("OPERATION FAILED")); self::_errorLog(date("Y-m-d H:i:s : ") .basename($_SERVER['PHP_SELF']) .sprintf(_("set printer attributes for printer %s: OPERATION FAILED"), $this->printer_uri),1); - - return false; - + + return false; } - // }}} -// REQUEST BUILDING - - // {{{ _setDocumentUri ($job_uri) - protected function _setDocumentUri () { - + // REQUEST BUILDING + protected function _setDocumentUri () + { $this->meta->document_uri = chr(0x45) // type uri . chr(0x00).chr(0x0c) // name-length . "document-uri" . self::_giveMeStringLength($this->document_uri) . $this->document_uri; - + self::_putDebug( "document uri is: ".$this->document_uri."\n"); $this->setup->document_uri = 1; - } - // }}} - // {{{ _stringUri () - protected function _stringUri () { - + + protected function _stringUri () + { self::_setDocumentUri(); - - if (!isset($this->setup->document_uri)) { + + if (!isset($this->setup->document_uri)) + { trigger_error(_("_stringUri: Document URI is not set: die"),E_USER_WARNING); self::_putDebug( _("_stringUri: Document URI is not set: die\n")); self::_errorLog("Document URI is not set, die",2); return FALSE; } unset ($this->setup->document_uri); - - if (!isset($this->setup->uri)) { + + if (!isset($this->setup->uri)) + { $this->getPrinters(); unset($this->jobs[count($this->jobs) - 1]); unset($this->jobs_uri[count($this->jobs) - 1]); unset($this->status[count($this->status) - 1]); - + if (array_key_exists(0,$this->available_printers)) + { self::setPrinterURI($this->available_printers[0]); - else { + } + else + { trigger_error(_("_stringUri: Printer URI is not set: die"),E_USER_WARNING); self::_putDebug( _("_stringUri: Printer URI is not set: die\n")); self::_errorLog("_stringUri: Printer URI is not set, die",2); return FALSE; - } } + } if (!isset($this->setup->charset)) + { $this->meta->charset = ""; - // self::setCharset('us-ascii'); + } if (!isset($this->setup->datatype)) + { self::setBinary(); - if (!isset($this->setup->uri)) { + } + if (!isset($this->setup->uri)) + { trigger_error(_("_stringUri: Printer URI is not set: die"),E_USER_WARNING); self::_putDebug( _("_stringUri: Printer URI is not set: die\n")); self::_errorLog("Printer URI is not set, die",2); return FALSE; - } + } if (!isset($this->setup->copies)) + { self::setCopies(1); - + } + if (!isset($this->setup->language)) + { self::setLanguage('en_us'); + } if (!isset($this->setup->mime_media_type)) + { self::setMimeMediaType(); + } unset ($this->setup->mime_media_type); - + if (!isset($this->setup->jobname)) + { if (is_readable($this->data)) + { self::setJobName(basename($this->data),true); + } else + { self::setJobName(); + } + } unset($this->setup->jobname); if (!isset($this->meta->username)) + { self::setUserName(); + } if (!isset($this->meta->fidelity)) + { $this->meta->fidelity = ''; - + } + if (!isset($this->meta->document_name)) + { $this->meta->document_name = ''; + } if (!isset($this->meta->sides)) + { $this->meta->sides = ''; - + } + if (!isset($this->meta->page_ranges)) + { $this->meta->page_ranges = ''; - + } + $jobattributes = ''; $operationattributes = ''; $printerattributes = ''; self::_buildValues($operationattributes,$jobattributes,$printerattributes); - + self::_setOperationId(); - + if (!isset($this->error_generation->request_body_malformed)) + { $this->error_generation->request_body_malformed = ""; - + } + $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number . chr(0x00) . chr (0x03) // Print-URI | operation-id . $this->meta->operation_id // request-id @@ -1234,72 +1412,98 @@ class ExtendedPrintIPP extends PrintIPP { . $this->meta->page_ranges . $jobattributes . chr(0x03); // end-of-attributes | end-of-attributes-tag - + self::_putDebug( sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob)); return TRUE; } - // }}} - - // {{{ _stringDocument ($job,$is_last) - protected function _stringDocument ($job,$is_last) { - - if ($is_last == false) - $is_last = chr(0x00); - else - $is_last = chr(0x01); - - if (!isset($this->setup->charset)) - self::setCharset('us-ascii'); - if (!isset($this->setup->datatype)) - self::setBinary(); - if (!isset($this->setup->uri)) { + + protected function _stringDocument ($job,$is_last) + { + if ($is_last == false) + { + $is_last = chr(0x00); + } + else + { + $is_last = chr(0x01); + } + + if (!isset($this->setup->charset)) + { + self::setCharset(); + } + if (!isset($this->setup->datatype)) + { + self::setBinary(); + } + + if (!isset($this->setup->uri)) + { $this->getPrinters(); unset($this->jobs[count($this->jobs) - 1]); unset($this->jobs_uri[count($this->jobs_uri) - 1]); unset($this->status[count($this->status) - 1]); - + if (array_key_exists(0,$this->available_printers)) + { self::setPrinterURI($this->available_printers[0]); - else { + } + else + { trigger_error(_("_stringJob: Printer URI is not set: die"),E_USER_WARNING); self::_putDebug( _("_stringJob: Printer URI is not set: die\n")); self::_errorLog(" Printer URI is not set, die",2); return FALSE; } } - + if (!isset($this->setup->copies)) + { $this->meta->copies = ""; - + } + if (!isset($this->setup->language)) + { self::setLanguage('en_us'); + } if (!isset($this->setup->mime_media_type)) + { $this->meta->mime_media_type = ""; + } if ($this->setup->datatype != "TEXT") + { unset ($this->setup->mime_media_type); - + } + if (!isset($this->meta->fidelity)) + { $this->meta->fidelity = ''; - + } + if (!isset($this->meta->document_name)) + { $this->meta->document_name = ''; + } if (!isset($this->meta->sides)) + { $this->meta->sides = ''; - + } + if (!isset($this->meta->page_ranges)) + { $this->meta->page_ranges = ''; - + } + $operationattributes = ''; $jobattributes = ''; $printerattributes = ''; self::_buildValues($operationattributes,$jobattributes,$printerattributes); - + self::_setOperationId(); - $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number . chr(0x00) . chr (0x06) // Send-Document | operation-id . $this->meta->operation_id // request-id @@ -1322,84 +1526,107 @@ class ExtendedPrintIPP extends PrintIPP { . self::_giveMeStringLength($is_last) . $is_last . chr(0x03); // end-of-attributes | end-of-attributes-tag - self::_putDebug( sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob)); return TRUE; } - // }}} - // {{{ _stringSendUri ($uri,$job,$is_last) - protected function _stringSendUri ($uri,$job,$is_last) { - + + protected function _stringSendUri ($uri,$job,$is_last) + { $this->document_uri = $uri; self::_setDocumentUri(); - - if (!isset($this->setup->document_uri)) { + + if (!isset($this->setup->document_uri)) + { trigger_error(_("_stringUri: Document URI is not set: die"),E_USER_WARNING); self::_putDebug( _("_stringUri: Document URI is not set: die\n")); self::_errorLog("Document URI is not set, die",2); return FALSE; } unset ($this->setup->document_uri); - - - if ($is_last == false) - $is_last = chr(0x00); - else - $is_last = chr(0x01); - - if (!isset($this->setup->charset)) - self::setCharset('us-ascii'); - if (!isset($this->setup->datatype)) - self::setBinary(); - if (!isset($this->setup->uri)) { + if ($is_last == false) + { + $is_last = chr(0x00); + } + else + { + $is_last = chr(0x01); + } + + if (!isset($this->setup->charset)) + { + self::setCharset(); + } + if (!isset($this->setup->datatype)) + { + self::setBinary(); + } + + if (!isset($this->setup->uri)) + { $this->getPrinters(); unset($this->jobs[count($this->jobs) - 1]); unset($this->jobs_uri[count($this->jobs_uri) - 1]); unset($this->status[count($this->status) - 1]); - + if (array_key_exists(0,$this->available_printers)) + { self::setPrinterURI($this->available_printers[0]); - else { + } + else + { trigger_error(_("_stringJob: Printer URI is not set: die"),E_USER_WARNING); self::_putDebug( _("_stringJob: Printer URI is not set: die\n")); self::_errorLog(" Printer URI is not set, die",2); return FALSE; } } - + if (!isset($this->setup->copies)) + { $this->meta->copies = ""; - + } + if (!isset($this->setup->language)) + { self::setLanguage('en_us'); + } if (!isset($this->setup->mime_media_type)) + { $this->meta->mime_media_type = ""; + } unset ($this->setup->mime_media_type); - + if (!isset($this->meta->fidelity)) + { $this->meta->fidelity = ''; - + } + if (!isset($this->meta->document_name)) + { $this->meta->document_name = ''; + } if (!isset($this->meta->sides)) + { $this->meta->sides = ''; - + } + if (!isset($this->meta->page_ranges)) + { $this->meta->page_ranges = ''; - + } + $operationattributes = ''; $jobattributes = ''; $printerattributes = ''; self::_buildValues($operationattributes,$jobattributes,$printerattributes); - + self::_setOperationId(); - $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number . chr(0x00) . chr (0x07) // Send-Uri | operation-id . $this->meta->operation_id // request-id @@ -1422,20 +1649,8 @@ class ExtendedPrintIPP extends PrintIPP { . self::_giveMeStringLength($is_last) . $is_last . chr(0x03); // end-of-attributes | end-of-attributes-tag - self::_putDebug( sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob)); return TRUE; } - // }}} - -}; - -/* - * Local variables: - * mode: php - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ -?> +} \ No newline at end of file diff --git a/htdocs/includes/printipp/PrintIPP.php b/htdocs/includes/printipp/PrintIPP.php index 9ed502c2d11..ffda9e8f1f7 100644 --- a/htdocs/includes/printipp/PrintIPP.php +++ b/htdocs/includes/printipp/PrintIPP.php @@ -1,5 +1,5 @@ _stringJob()) + { return FALSE; - - if (is_readable($this->data)){ + } + + if (is_readable($this->data)) + { self::_putDebug( _("Printing a FILE\n"),3); - + $this->output = $this->stringjob; - + if ($this->setup->datatype == "TEXT") + { $this->output .= chr(0x16); - - + } + $post_values = array( "Content-Type" => "application/ipp", "Data" => $this->output, "File" => $this->data); - + if ($this->setup->datatype == "TEXT" && !isset($this->setup->noFormFeed)) + { $post_values = array_merge($post_values,array("Filetype"=>"TEXT")); - - } else { + } + } + else + { self::_putDebug( _("Printing DATA\n"),3); - + $this->output = $this->stringjob; $this->output .= $this->datahead; $this->output .= $this->data; @@ -99,25 +90,25 @@ class PrintIPP extends BasicIPP { $post_values = array( "Content-Type" => "application/ipp", "Data" => $this->output); - - - } - - if (self::_sendHttp ($post_values,$this->paths['printers'])) { - - if(self::_parseServerOutput()) { + } + + if (self::_sendHttp ($post_values,$this->paths['printers'])) + { + if(self::_parseServerOutput()) + { $this->_getJobId(); $this->_getJobUri(); $this->_parseJobAttributes(); - } else { + } + else + { $this->jobs = array_merge($this->jobs,array('')); $this->jobs_uri = array_merge($this->jobs_uri,array('')); } - } - - if (isset($this->serveroutput) && isset($this->serveroutput->status)) { - + + if (isset($this->serveroutput) && isset($this->serveroutput->status)) + { $this->status = array_merge($this->status,array($this->serveroutput->status)); if ($this->serveroutput->status == "successfull-ok") @@ -131,138 +122,174 @@ class PrintIPP extends BasicIPP { self::_errorLog(sprintf("printing job: ",$this->last_job) .$this->serveroutput->status,1); if ($this->with_exceptions) { - throw new ippException(sprintf("job status: %s", + throw new ippException(sprintf("job status: %s", $this->serveroutput->status)); } } return $this->serveroutput->status; - - } + } $this->status = array_merge($this->status,array("OPERATION FAILED")); $this->jobs = array_merge($this->jobs,array("")); $this->jobs_uri = array_merge($this->jobs_uri,array("")); self::_errorLog("printing job : OPERATION FAILED",1); - - return false; - } - // }}} - // {{{ cancelJob ($job_uri) - public function cancelJob ($job_uri) { - + return false; + } + + public function cancelJob ($job_uri) + { $this->jobs = array_merge($this->jobs,array("")); $this->jobs_uri = array_merge($this->jobs_uri,array("")); - + self::_putDebug( sprintf("*************************\nDate: %s\n*************************\n\n",date('Y-m-d H:i:s'))); - + if (!$this->_stringCancel($job_uri)) - return FALSE; - + { + return FALSE; + } + self::_putDebug( _("Cancelling Job $job_uri\n"),3); - + $this->output = $this->stringjob; - + $post_values = array( "Content-Type"=>"application/ipp", "Data"=>$this->output); - + if (self::_sendHttp ($post_values,$this->paths['jobs'])) + { self::_parseServerOutput(); - - - if (isset($this->serveroutput) && isset($this->serveroutput->status)) { - + } + + if (isset($this->serveroutput) && isset($this->serveroutput->status)) + { $this->status = array_merge($this->status,array($this->serveroutput->status)); if ($this->serveroutput->status == "successfull-ok") + { self::_errorLog("cancelling job $job_uri: ".$this->serveroutput->status,3); - else - self::_errorLog("cancelling job $job_uri: ".$this->serveroutput->status,1); - return $this->serveroutput->status; - } + else + { + self::_errorLog("cancelling job $job_uri: ".$this->serveroutput->status,1); + } + return $this->serveroutput->status; + } - $this->status = array_merge($this->status,array("OPERATION FAILED")); - self::_errorLog("cancelling job : OPERATION FAILED",3); - - return false; + $this->status = array_merge($this->status,array("OPERATION FAILED")); + self::_errorLog("cancelling job : OPERATION FAILED",3); + + return false; } - // }}} - // {{{ validateJob () - public function validateJob () { - + public function validateJob () + { $this->jobs = array_merge($this->jobs,array("")); $this->jobs_uri = array_merge($this->jobs_uri,array("")); - + $this->serveroutput->response = ''; self::_putDebug( sprintf("*************************\nDate: %s\n*************************\n\n",date('Y-m-d H:i:s'))); - - - self::_putDebug( _("Validate Job\n"),2); - - if (!isset($this->setup->charset)) - self::setCharset('us-ascii'); - if (!isset($this->setup->datatype)) - self::setBinary(); - if (!isset($this->setup->uri)) { + self::_putDebug( _("Validate Job\n"),2); + + if (!isset($this->setup->charset)) + { + self::setCharset(); + } + if (!isset($this->setup->datatype)) + { + self::setBinary(); + } + + if (!isset($this->setup->uri)) + { $this->getPrinters(); unset($this->jobs[count($this->jobs) - 1]); unset($this->jobs_uri[count($this->jobs_uri) - 1]); unset($this->status[count($this->status) - 1]); - + if (array_key_exists(0,$this->available_printers)) + { self::setPrinterURI($this->available_printers[0]); - else { + } + else + { trigger_error(_("_stringJob: Printer URI is not set: die"),E_USER_WARNING); self::_putDebug( _("_stringJob: Printer URI is not set: die\n"),3); self::_errorLog(" Printer URI is not set, die",2); return FALSE; } } - + if (!isset($this->meta->copies)) + { self::setCopies(1); + } + if (!isset($this->setup->copies)) + { self::setCopies(1); - + } + if (!isset($this->setup->language)) + { self::setLanguage('en_us'); + } if (!isset($this->setup->mime_media_type)) + { self::setMimeMediaType(); + } + if ($this->setup->datatype != "TEXT") - unset ($this->setup->mime_media_type); - + { + unset ($this->setup->mime_media_type); + } + if (!isset($this->setup->jobname)) + { if (is_readable($this->data)) + { self::setJobName(basename($this->data),true); + } else + { self::setJobName(); + } + } unset($this->setup->jobname); if (!isset($this->meta->username)) + { self::setUserName(); + } if (!isset($this->meta->fidelity)) + { $this->meta->fidelity = ''; - + } + if (!isset($this->meta->document_name)) + { $this->meta->document_name = ''; + } if (!isset($this->meta->sides)) + { $this->meta->sides = ''; - + } + if (!isset($this->meta->page_ranges)) + { $this->meta->page_ranges = ''; - + } + $jobattributes = ''; $operationattributes = ''; $printerattributes = ''; self::_buildValues ($operationattributes,$jobattributes,$printerattributes); - + self::_setOperationId(); $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number @@ -284,43 +311,45 @@ class PrintIPP extends BasicIPP { . $this->meta->page_ranges . $jobattributes . chr(0x03); // end-of-attributes | end-of-attributes-tag - self::_putDebug( sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob)); - + $this->output = $this->stringjob; - + $post_values = array( "Content-Type"=>"application/ipp", "Data"=>$this->output); - + if (self::_sendHttp ($post_values,$this->paths['printers'])) - if(self::_parseServerOutput()) - self::_parseAttributes(); - - - if (isset($this->serveroutput) && isset($this->serveroutput->status)) { - + { + if(self::_parseServerOutput()) + { + self::_parseAttributes(); + } + } + + if (isset($this->serveroutput) && isset($this->serveroutput->status)) + { $this->status = array_merge($this->status,array($this->serveroutput->status)); if ($this->serveroutput->status == "successfull-ok") + { self::_errorLog("validate job: ".$this->serveroutput->status,3); - else - self::_errorLog("validate job: ".$this->serveroutput->status,1); - - return $this->serveroutput->status; - } + else + { + self::_errorLog("validate job: ".$this->serveroutput->status,1); + } + return $this->serveroutput->status; + } - $this->status = array_merge($this->status,array("OPERATION FAILED")); - self::_errorLog("validate job : OPERATION FAILED",3); - - return false; + $this->status = array_merge($this->status,array("OPERATION FAILED")); + self::_errorLog("validate job : OPERATION FAILED",3); + + return false; } - // }}} - // {{{ getPrinterAttributes() - public function getPrinterAttributes() { - + public function getPrinterAttributes() + { $this->jobs = array_merge($this->jobs,array("")); $this->jobs_uri = array_merge($this->jobs_uri,array("")); @@ -330,32 +359,42 @@ class PrintIPP extends BasicIPP { self::_setOperationId(); $this->parsed = array(); unset($this->printer_attributes); - - if (!isset($this->setup->uri)) { + + if (!isset($this->setup->uri)) + { $this->getPrinters(); unset($this->jobs[count($this->jobs) - 1]); unset($this->jobs_uri[count($this->jobs_uri) - 1]); unset($this->status[count($this->status) - 1]); - + if (array_key_exists(0,$this->available_printers)) + { self::setPrinterURI($this->available_printers[0]); - else { + } + else + { trigger_error(_("_stringJob: Printer URI is not set: die"),E_USER_WARNING); self::_putDebug( _("_stringJob: Printer URI is not set: die\n"),3); self::_errorLog(" Printer URI is not set, die",2); return FALSE; } } - + if (!isset($this->setup->charset)) - self::setCharset('us-ascii'); - + { + self::setCharset(); + } + if (!isset($this->setup->language)) + { self::setLanguage('en_us'); + } if (!isset($this->meta->username)) + { self::setUserName(); - + } + $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number . chr(0x00) . chr (0x0b) // Print-URI | operation-id . $this->meta->operation_id // request-id @@ -366,109 +405,137 @@ class PrintIPP extends BasicIPP { . $this->meta->username . $printerattributes . chr(0x03); // end-of-attributes | end-of-attributes-tag - + self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob)); - + self::_putDebug(sprintf(_("Getting printer attributes of %s\n"),$this->printer_uri),2); - + $this->output = $this->stringjob; - + $post_values = array( "Content-Type"=>"application/ipp", "Data"=>$this->output); - + if (self::_sendHttp ($post_values,$this->paths['root'])) + { if (self::_parseServerOutput()) + { self::_parsePrinterAttributes(); - + } + } + $this->attributes = &$this->printer_attributes; - - if (isset($this->serveroutput) && isset($this->serveroutput->status)) { - + + if (isset($this->serveroutput) && isset($this->serveroutput->status)) + { $this->status = array_merge($this->status,array($this->serveroutput->status)); - + if ($this->serveroutput->status == "successfull-ok") + { self::_errorLog(sprintf(_("getting printer attributes of %s: %s"),$this->printer_uri, $this->serveroutput->status),3); + } else + { self::_errorLog(sprintf(_("getting printer attributes of %s: %s"),$this->printer_uri, $this->serveroutput->status),1); - - return $this->serveroutput->status; } - $this->status = array_merge($this->status,array("OPERATION FAILED")); - self::_errorLog(date("Y-m-d H:i:s : ") - .basename($_SERVER['PHP_SELF']) - .sprintf(_("getting printer's attributes of %s : OPERATION FAILED"), - $this->printer_uri),3); - - return false; - } - // }}} + return $this->serveroutput->status; + } - // {{{ getJobs ($my_jobs=true,$limit=0,$which_jobs=""); - public function getJobs($my_jobs=true,$limit=0,$which_jobs="not-completed",$subset=false) { - + $this->status = array_merge($this->status,array("OPERATION FAILED")); + self::_errorLog(date("Y-m-d H:i:s : ") + .basename($_SERVER['PHP_SELF']) + .sprintf(_("getting printer's attributes of %s : OPERATION FAILED"), + $this->printer_uri),3); + + return false; + } + + public function getJobs($my_jobs=true,$limit=0,$which_jobs="not-completed",$subset=false) + { $this->jobs = array_merge($this->jobs,array("")); $this->jobs_uri = array_merge($this->jobs_uri,array("")); self::_setOperationId(); $this->parsed = array(); unset($this->printer_attributes); - - if (!isset($this->setup->uri)) { + + if (!isset($this->setup->uri)) + { $this->getPrinters(); unset($this->jobs[count($this->jobs) - 1]); unset($this->jobs_uri[count($this->jobs_uri) - 1]); unset($this->status[count($this->status) - 1]); - + if (array_key_exists(0,$this->available_printers)) + { self::setPrinterURI($this->available_printers[0]); - else { + } + else + { trigger_error(_("getJobs: Printer URI is not set: die"),E_USER_WARNING); self::_putDebug( _("_stringJob: Printer URI is not set: die\n"),3); self::_errorLog("getJobs: Printer URI is not set, die",2); return FALSE; } } - + if (!isset($this->setup->charset)) - self::setCharset('us-ascii'); - + { + self::setCharset(); + } + if (!isset($this->setup->language)) + { self::setLanguage('en_us'); + } if (!isset($this->meta->username)) + { self::setUserName(); + } - if ($limit) { + if ($limit) + { $limit = self::_integerBuild($limit); $this->meta->limit = chr(0x21) // integer . self::_giveMeStringLength('limit') . 'limit' . self::_giveMeStringLength($limit) . $limit; - } else + } + else + { $this->meta->limit = ''; - + } + if ($which_jobs == 'completed') + { $this->meta->which_jobs = chr(0x44) // keyword . self::_giveMeStringLength('which-jobs') . 'which-jobs' . self::_giveMeStringLength($which_jobs) . $which_jobs; + } else + { $this->meta->which_jobs = ""; + } if ($my_jobs) + { $this->meta->my_jobs = chr(0x22) // boolean . self::_giveMeStringLength('my-jobs') . 'my-jobs' . self::_giveMeStringLength(chr(0x01)) . chr(0x01); + } else + { $this->meta->my_jobs = ''; - + } + $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number . chr(0x00) . chr (0x0A) // Get-Jobs | operation-id . $this->meta->operation_id // request-id @@ -479,9 +546,9 @@ class PrintIPP extends BasicIPP { . $this->meta->username . $this->meta->limit . $this->meta->which_jobs - . $this->meta->my_jobs - ; - if ($subset) { + . $this->meta->my_jobs; + if ($subset) + { $this->stringjob .= chr(0x44) // keyword . self::_giveMeStringLength('requested-attributes') @@ -502,106 +569,122 @@ class PrintIPP extends BasicIPP { . self::_giveMeStringLength('') . '' . self::_giveMeStringLength('job-state-reason') - . 'job-state-reason' - ; + . 'job-state-reason'; } - else { # cups 1.4.4 doesn't return much of anything without this + else + { # cups 1.4.4 doesn't return much of anything without this $this->stringjob .= chr(0x44) // keyword . self::_giveMeStringLength('requested-attributes') . 'requested-attributes' . self::_giveMeStringLength('all') - . 'all' - ; + . 'all'; } $this->stringjob .= chr(0x03); // end-of-attributes | end-of-attributes-tag - + self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob)); - + self::_putDebug(sprintf(_("getting jobs of %s\n"),$this->printer_uri),2); - + $this->output = $this->stringjob; - + $post_values = array( "Content-Type"=>"application/ipp", "Data"=>$this->output); - + if (self::_sendHttp ($post_values,$this->paths['jobs'])) + { if (self::_parseServerOutput()) + { self::_parseJobsAttributes(); - + } + } + $this->attributes = &$this->jobs_attributes; - - if (isset($this->serveroutput) && isset($this->serveroutput->status)) { - + if (isset($this->serveroutput) && isset($this->serveroutput->status)) + { $this->status = array_merge($this->status,array($this->serveroutput->status)); - + if ($this->serveroutput->status == "successfull-ok") + { self::_errorLog(sprintf(_("getting jobs of printer %s: "),$this->printer_uri) .$this->serveroutput->status,3); + } else + { self::_errorLog(sprintf(_("getting jobs of printer %s: "),$this->printer_uri) .$this->serveroutput->status,1); - + } + return $this->serveroutput->status; - } - + } + $this->status = array_merge($this->status,array("OPERATION FAILED")); self::_errorLog(date("Y-m-d H:i:s : ") .basename($_SERVER['PHP_SELF']) .sprintf(_("getting jobs of %s : OPERATION FAILED"), $this->printer_uri),3); - + return false; } - // }}} - // {{{ getJobAttributes ($job_uri,subset="false",$attributes_group="all"); - public function getJobAttributes($job_uri,$subset=false,$attributes_group="all") { - + + public function getJobAttributes($job_uri,$subset=false,$attributes_group="all") + { $this->jobs = array_merge($this->jobs,array("")); $this->jobs_uri = array_merge($this->jobs_uri,array("")); - - if (!$job_uri) { + + if (!$job_uri) + { trigger_error(_("getJobAttributes: Job URI is not set, die.")); return FALSE; } - + self::_setOperationId(); $this->parsed = array(); unset($this->printer_attributes); - - if (!isset($this->setup->uri)) { + + if (!isset($this->setup->uri)) + { $this->getPrinters(); unset($this->jobs[count($this->jobs) - 1]); unset($this->jobs_uri[count($this->jobs_uri) - 1]); unset($this->status[count($this->status) - 1]); - + if (array_key_exists(0,$this->available_printers)) + { self::setPrinterURI($this->available_printers[0]); - else { + } + else + { trigger_error(_("getJobs: Printer URI is not set: die"),E_USER_WARNING); self::_putDebug( _("_stringJob: Printer URI is not set: die\n"),3); self::_errorLog("getJobs: Printer URI is not set, die",2); return FALSE; - } } - + } + if (!isset($this->setup->charset)) - self::setCharset('us-ascii'); - + { + self::setCharset(); + } + if (!isset($this->setup->language)) + { self::setLanguage('en_us'); + } if (!isset($this->meta->username)) + { self::setUserName(); + } $this->meta->job_uri = chr(0x45) // URI . self::_giveMeStringLength('job-uri') . 'job-uri' . self::_giveMeStringLength($job_uri) . $job_uri; - + $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number . chr(0x00) . chr (0x09) // Get-Job-Attributes | operation-id . $this->meta->operation_id // request-id @@ -609,10 +692,10 @@ class PrintIPP extends BasicIPP { . $this->meta->charset . $this->meta->language . $this->meta->job_uri - . $this->meta->username - ; - if ($subset) - $this->stringjob .= + . $this->meta->username; + if ($subset) + { + $this->stringjob .= chr(0x44) // keyword . self::_giveMeStringLength('requested-attributes') . 'requested-attributes' @@ -632,10 +715,12 @@ class PrintIPP extends BasicIPP { . self::_giveMeStringLength('') . '' . self::_giveMeStringLength('job-state-reason') - . 'job-state-reason' - ; - elseif($attributes_group) { - switch($attributes_group) { + . 'job-state-reason'; + } + elseif($attributes_group) + { + switch($attributes_group) + { case 'job-template': break; case 'job-description': @@ -646,127 +731,116 @@ class PrintIPP extends BasicIPP { trigger_error(_('not a valid attribute group: ').$attributes_group,E_USER_NOTICE); $attributes_group = ''; break; - } + } $this->stringjob .= chr(0x44) // keyword . self::_giveMeStringLength('requested-attributes') . 'requested-attributes' . self::_giveMeStringLength($attributes_group) . $attributes_group; - } + } $this->stringjob .= chr(0x03); // end-of-attributes | end-of-attributes-tag - + self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob)); - + self::_putDebug(sprintf(_("getting jobs of %s\n"),$this->printer_uri),2); - + $this->output = $this->stringjob; - + $post_values = array( "Content-Type"=>"application/ipp", "Data"=>$this->output); - + if (self::_sendHttp ($post_values,$this->paths['jobs'])) + { if (self::_parseServerOutput()) + { self::_parseJobAttributes(); - + } + } + $this->attributes = &$this->job_attributes; - - if (isset($this->serveroutput) && isset($this->serveroutput->status)) { - + + if (isset($this->serveroutput) && isset($this->serveroutput->status)) + { $this->status = array_merge($this->status,array($this->serveroutput->status)); - + if ($this->serveroutput->status == "successfull-ok") + { self::_errorLog(sprintf(_("getting job attributes for %s: "),$job_uri) .$this->serveroutput->status,3); + } else + { self::_errorLog(sprintf(_("getting job attributes for %s: "),$job_uri) .$this->serveroutput->status,1); - + } + return $this->serveroutput->status; - } - + } + $this->status = array_merge($this->status,array("OPERATION FAILED")); self::_errorLog(date("Y-m-d H:i:s : ") .basename($_SERVER['PHP_SELF']) .sprintf(_("getting jobs attributes of %s : OPERATION FAILED"), $job_uri),3); - - return false; + + return false; } - // }}} - - // {{{ getPrinters(); - public function getPrinters() { - + public function getPrinters() + { // placeholder for vendor extension operation (getAvailablePrinters for CUPS) $this->jobs = array_merge($this->jobs,array('')); $this->jobs_uri = array_merge($this->jobs_uri,array('')); $this->status = array_merge($this->status,array('')); } - // }}} -/****************** -* -* DEVELOPPEMENT FUNCTIONS -* -*******************/ - - // {{{ generateError($error) - public function generateError ($error) { - switch ($error) { + public function generateError ($error) + { + switch ($error) + { case "request_body_malformed": $this->error_generation->request_body_malformed = chr(0xFF); break; default: true; break; - } - // }}} + } - // {{{ resetError ($error) trigger_error(sprintf(_('Setting Error %s'),$error),E_USER_NOTICE); } - public function resetError ($error) { + public function resetError ($error) + { unset ($this->error_generation->$error); trigger_error(sprintf(_('Reset Error %s'),$error),E_USER_NOTICE); } - // }}} -/****************** -* -* PROTECTED FUNCTIONS -* -*******************/ - -// SETUP - - // {{{ _setOperationId () - protected function _setOperationId () { + // SETUP + protected function _setOperationId () + { $prepend = ''; $this->operation_id += 1; $this->meta->operation_id = self::_integerBuild($this->operation_id); self::_putDebug( "operation id is: ".$this->operation_id."\n",2); } - // }}} - // {{{ _setJobId() - protected function _setJobId() { + protected function _setJobId() + { $this->meta->jobid +=1; $prepend = ''; $prepend_length = 4 - strlen($this->meta->jobid); for ($i = 0; $i < $prepend_length ; $i++ ) + { $prepend .= '0'; + } return $prepend.$this->meta->jobid; } - // }}} - // {{{ _setJobUri ($job_uri) - protected function _setJobUri ($job_uri) { - + protected function _setJobUri ($job_uri) + { $this->meta->job_uri = chr(0x45) // type uri . chr(0x00).chr(0x07) // name-length . "job-uri" @@ -776,441 +850,490 @@ class PrintIPP extends BasicIPP { self::_putDebug( "job-uri is: ".$job_uri."\n",2); } - // }}} - -// RESPONSE PARSING - - // {{{ _parsePrinterAttributes() - protected function _parsePrinterAttributes() { + // RESPONSE PARSING + protected function _parsePrinterAttributes() + { //if (!preg_match('#successful#',$this->serveroutput->status)) // return false; $k = -1; + $l = 0; for ($i = 0 ; $i < count($this->serveroutput->response) ; $i++) + { for ($j = 0 ; $j < (count($this->serveroutput->response[$i]) - 1) ; $j ++) - if (!empty($this->serveroutput->response[$i][$j]['name'])) { + { + if (!empty($this->serveroutput->response[$i][$j]['name'])) + { $k++; $l = 0; $this->parsed[$k]['range'] = $this->serveroutput->response[$i]['attributes']; $this->parsed[$k]['name'] = $this->serveroutput->response[$i][$j]['name']; $this->parsed[$k]['type'] = $this->serveroutput->response[$i][$j]['type']; $this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value']; - } else { + } + else + { $l ++; $this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value']; } + } + } $this->serveroutput->response = array(); - - $this->printer_attributes = new stdClass(); - for ($i = 0 ; $i < count($this->parsed) ; $i ++) { + + $this->printer_attributes = new \stdClass(); + for ($i = 0 ; $i < count($this->parsed) ; $i ++) + { $name = $this->parsed[$i]['name']; $php_name = str_replace('-','_',$name); $type = $this->parsed[$i]['type']; $range = $this->parsed[$i]['range']; - $this->printer_attributes->$php_name = new stdClass(); + $this->printer_attributes->$php_name = new \stdClass(); $this->printer_attributes->$php_name->_type = $type; $this->printer_attributes->$php_name->_range = $range; - for ($j = 0 ; $j < (count($this->parsed[$i]) - 3) ; $j ++) { + for ($j = 0 ; $j < (count($this->parsed[$i]) - 3) ; $j ++) + { $value = $this->parsed[$i][$j]; $index = '_value'.$j; $this->printer_attributes->$php_name->$index = $value; } } - + $this->parsed = array(); - - } - // }}} - - // {{{ _parseJobsAttributes() - protected function _parseJobsAttributes() { + protected function _parseJobsAttributes() + { //if ($this->serveroutput->status != "successfull-ok") // return false; - + $job = -1; - for ($i = 0 ; $i < count($this->serveroutput->response) ; $i++) { + $l = 0; + for ($i = 0 ; $i < count($this->serveroutput->response) ; $i++) + { if ($this->serveroutput->response[$i]['attributes'] == "job-attributes") + { $job ++; + } $k = -1; for ($j = 0 ; $j < (count($this->serveroutput->response[$i]) - 1) ; $j ++) - if (!empty($this->serveroutput->response[$i][$j]['name'])) { + { + if (!empty($this->serveroutput->response[$i][$j]['name'])) + { $k++; $l = 0; $this->parsed[$job][$k]['range'] = $this->serveroutput->response[$i]['attributes']; $this->parsed[$job][$k]['name'] = $this->serveroutput->response[$i][$j]['name']; $this->parsed[$job][$k]['type'] = $this->serveroutput->response[$i][$j]['type']; $this->parsed[$job][$k][$l] = $this->serveroutput->response[$i][$j]['value']; - } else { + } + else + { $l ++; $this->parsed[$job][$k][$l] = $this->serveroutput->response[$i][$j]['value']; - } - } - - $this->serveroutput->response = array(); - $this->jobs_attributes = new stdClass(); - for ($job_nbr = 0 ; $job_nbr <= $job ; $job_nbr ++) { - $job_index = "job_".$job_nbr; - $this->jobs_attributes->$job_index = new stdClass(); - for ($i = 0 ; $i < count($this->parsed[$job_nbr]) ; $i ++) { - $name = $this->parsed[$job_nbr][$i]['name']; - $php_name = str_replace('-','_',$name); - $type = $this->parsed[$job_nbr][$i]['type']; - $range = $this->parsed[$job_nbr][$i]['range']; - $this->jobs_attributes->$job_index->$php_name = new stdClass(); - $this->jobs_attributes->$job_index->$php_name->_type = $type; - $this->jobs_attributes->$job_index->$php_name->_range = $range; - for ($j = 0 ; $j < (count($this->parsed[$job_nbr][$i]) - 3) ; $j ++) { - # This causes incorrect parsing of integer job attributes. - # 2010-08-16 - # bpkroth - #$value = self::_interpretAttribute($name,$type,$this->parsed[$job_nbr][$i][$j]); - $value = $this->parsed[$job_nbr][$i][$j]; - $index = '_value'.$j; - $this->jobs_attributes->$job_index->$php_name->$index = $value; - } - } - } - - $this->parsed = array(); - - - } - // }}} - - // {{{ _readAttribute($attributes_type,$ji,&$collection=false) - protected function _readAttribute($attributes_type) { - - $tag = ord($this->serveroutput->body[$this->_parsing->offset]); - - $this->_parsing->offset += 1; - $j = $this->index; - - $tag = self::_readTag($tag); - - switch ($tag) { - case "begCollection": //RFC3382 (BLIND CODE) - if ($this->end_collection) - $this->index --; - $this->end_collection = false; - $this->serveroutput->response[$attributes_type][$j]['type'] = "collection"; - self::_putDebug( "tag is: begCollection\n"); - self::_readAttributeName ($attributes_type,$j); - if (!$this->serveroutput->response[$attributes_type][$j]['name']) { // it is a multi-valued collection - $this->collection_depth ++; - $this->index --; - $this->collection_nbr[$this->collection_depth] ++; - } else { - $this->collection_depth ++; - if ($this->collection_depth == 0) - $this->collection = (object) 'collection'; - if (array_key_exists($this->collection_depth,$this->collection_nbr)) - $this->collection_nbr[$this->collection_depth] ++; - else - $this->collection_nbr[$this->collection_depth] = 0; - unset($this->end_collection); - - } - self::_readValue ("begCollection",$attributes_type,$j); - break; - case "endCollection": //RFC3382 (BLIND CODE) - $this->serveroutput->response[$attributes_type][$j]['type'] = "collection"; - self::_putDebug( "tag is: endCollection\n"); - self::_readAttributeName ($attributes_type,$j,0); - self::_readValue ('name',$attributes_type,$j,0); - $this->collection_depth --; - $this->collection_key[$this->collection_depth] = 0; - $this->end_collection = true; - break; - case "memberAttrName": // RFC3382 (BLIND CODE) - $this->serveroutput->response[$attributes_type][$j]['type'] = "memberAttrName"; - $this->index -- ; - self::_putDebug( "tag is: memberAttrName\n"); - self::_readCollection ($attributes_type,$j); - break; - - default: - $this->collection_depth = -1; - $this->collection_key = array(); - $this->collection_nbr = array(); - $this->serveroutput->response[$attributes_type][$j]['type'] = $tag; - self::_putDebug( "tag is: $tag\n"); - $attribute_name = self::_readAttributeName ($attributes_type,$j); - if (!$attribute_name) - $attribute_name = $this->attribute_name; - else - $this->attribute_name = $attribute_name; - $value = self::_readValue ($tag,$attributes_type,$j); - $this->serveroutput->response[$attributes_type][$j]['value'] = - self::_interpretAttribute($attribute_name,$tag,$this->serveroutput->response[$attributes_type][$j]['value']); - break; - - } - return; - } - // }}} - - // {{{ _readTag($tag) - protected function _readTag($tag) { - - switch ($tag) { - case 0x10: - $tag = "unsupported"; - break; - case 0x11: - $tag = "reserved for 'default'"; - break; - case 0x12: - $tag = "unknown"; - break; - case 0x13: - $tag = "no-value"; - break; - case 0x15: // RFC 3380 - $tag = "not-settable"; - break; - case 0x16: // RFC 3380 - $tag = "delete-attribute"; - break; - case 0x17: // RFC 3380 - $tag = "admin-define"; - break; - case 0x20: - $tag = "IETF reserved (generic integer)"; - break; - case 0x21: - $tag = "integer"; - break; - case 0x22: - $tag = "boolean"; - break; - case 0x23: - $tag = "enum"; - break; - case 0x30: - $tag = "octetString"; - break; - case 0x31: - $tag = "datetime"; - break; - case 0x32: - $tag = "resolution"; - break; - case 0x33: - $tag = "rangeOfInteger"; - break; - case 0x34: //RFC3382 (BLIND CODE) - $tag = "begCollection"; - break; - case 0x35: - $tag = "textWithLanguage"; - break; - case 0x36: - $tag = "nameWithLanguage"; - break; - case 0x37: //RFC3382 (BLIND CODE) - $tag = "endCollection"; - break; - case 0x40: - $tag = "IETF reserved text string"; - break; - case 0x41: - $tag = "textWithoutLanguage"; - break; - case 0x42: - $tag = "nameWithoutLanguage"; - break; - case 0x43: - $tag = "IETF reserved for future"; - break; - case 0x44: - $tag = "keyword"; - break; - case 0x45: - $tag = "uri"; - break; - case 0x46: - $tag = "uriScheme"; - break; - case 0x47: - $tag = "charset"; - break; - case 0x48: - $tag = "naturalLanguage"; - break; - case 0x49: - $tag = "mimeMediaType"; - break; - case 0x4A: // RFC3382 (BLIND CODE) - $tag = "memberAttrName"; - break; - case 0x7F: - $tag = "extended type"; - break; - default: - - if ($tag >= 0x14 && $tag < 0x15 && $tag > 0x17 && $tag <= 0x1f) - $tag = "out-of-band"; - elseif (0x24 <= $tag && $tag <= 0x2f) - $tag = "new integer type"; - elseif (0x38 <= $tag && $tag <= 0x3F) - $tag = "new octet-stream type"; - elseif (0x4B <= $tag && $tag <= 0x5F) - $tag = "new character string type"; - elseif ((0x60 <= $tag && $tag < 0x7f) || $tag >= 0x80 ) - $tag = "IETF reserved for future"; - else - $tag = sprintf("UNKNOWN: 0x%x (%u)",$tag,$tag); - - break; } - return $tag; - } - // }}} + } + } - // {{{ _readCollection($attributes_type,$j,&$collection) - protected function _readCollection($attributes_type,$j) { - + $this->serveroutput->response = array(); + $this->jobs_attributes = new \stdClass(); + for ($job_nbr = 0 ; $job_nbr <= $job ; $job_nbr ++) + { + $job_index = "job_".$job_nbr; + $this->jobs_attributes->$job_index = new \stdClass(); + for ($i = 0 ; $i < count($this->parsed[$job_nbr]) ; $i ++) + { + $name = $this->parsed[$job_nbr][$i]['name']; + $php_name = str_replace('-','_',$name); + $type = $this->parsed[$job_nbr][$i]['type']; + $range = $this->parsed[$job_nbr][$i]['range']; + $this->jobs_attributes->$job_index->$php_name = new \stdClass(); + $this->jobs_attributes->$job_index->$php_name->_type = $type; + $this->jobs_attributes->$job_index->$php_name->_range = $range; + for ($j = 0 ; $j < (count($this->parsed[$job_nbr][$i]) - 3) ; $j ++) + { + # This causes incorrect parsing of integer job attributes. + # 2010-08-16 + # bpkroth + #$value = self::_interpretAttribute($name,$type,$this->parsed[$job_nbr][$i][$j]); + $value = $this->parsed[$job_nbr][$i][$j]; + $index = '_value'.$j; + $this->jobs_attributes->$job_index->$php_name->$index = $value; + } + } + } + + $this->parsed = array(); + } + + protected function _readAttribute($attributes_type) + { + $tag = ord($this->serveroutput->body[$this->_parsing->offset]); + + $this->_parsing->offset += 1; + $j = $this->index; + + $tag = self::_readTag($tag); + + switch ($tag) + { + case "begCollection": //RFC3382 (BLIND CODE) + if ($this->end_collection) + { + $this->index --; + } + $this->end_collection = false; + $this->serveroutput->response[$attributes_type][$j]['type'] = "collection"; + self::_putDebug( "tag is: begCollection\n"); + self::_readAttributeName ($attributes_type,$j); + if (!$this->serveroutput->response[$attributes_type][$j]['name']) + { // it is a multi-valued collection + $this->collection_depth ++; + $this->index --; + $this->collection_nbr[$this->collection_depth] ++; + } + else + { + $this->collection_depth ++; + if ($this->collection_depth == 0) + { + $this->collection = (object) 'collection'; + } + if (array_key_exists($this->collection_depth,$this->collection_nbr)) + { + $this->collection_nbr[$this->collection_depth] ++; + } + else + { + $this->collection_nbr[$this->collection_depth] = 0; + } + unset($this->end_collection); + } + self::_readValue ("begCollection",$attributes_type,$j); + break; + case "endCollection": //RFC3382 (BLIND CODE) + $this->serveroutput->response[$attributes_type][$j]['type'] = "collection"; + self::_putDebug( "tag is: endCollection\n"); + self::_readAttributeName ($attributes_type,$j,0); + self::_readValue ('name',$attributes_type,$j,0); + $this->collection_depth --; + $this->collection_key[$this->collection_depth] = 0; + $this->end_collection = true; + break; + case "memberAttrName": // RFC3382 (BLIND CODE) + $this->serveroutput->response[$attributes_type][$j]['type'] = "memberAttrName"; + $this->index -- ; + self::_putDebug( "tag is: memberAttrName\n"); + self::_readCollection ($attributes_type,$j); + break; + + default: + $this->collection_depth = -1; + $this->collection_key = array(); + $this->collection_nbr = array(); + $this->serveroutput->response[$attributes_type][$j]['type'] = $tag; + self::_putDebug( "tag is: $tag\n"); + $attribute_name = self::_readAttributeName ($attributes_type,$j); + if (!$attribute_name) + { + $attribute_name = $this->attribute_name; + } + else + { + $this->attribute_name = $attribute_name; + } + $value = self::_readValue ($tag,$attributes_type,$j); + $this->serveroutput->response[$attributes_type][$j]['value'] = + self::_interpretAttribute($attribute_name,$tag,$this->serveroutput->response[$attributes_type][$j]['value']); + break; + } + return; + } + + protected function _readTag($tag) + { + switch ($tag) + { + case 0x10: + $tag = "unsupported"; + break; + case 0x11: + $tag = "reserved for 'default'"; + break; + case 0x12: + $tag = "unknown"; + break; + case 0x13: + $tag = "no-value"; + break; + case 0x15: // RFC 3380 + $tag = "not-settable"; + break; + case 0x16: // RFC 3380 + $tag = "delete-attribute"; + break; + case 0x17: // RFC 3380 + $tag = "admin-define"; + break; + case 0x20: + $tag = "IETF reserved (generic integer)"; + break; + case 0x21: + $tag = "integer"; + break; + case 0x22: + $tag = "boolean"; + break; + case 0x23: + $tag = "enum"; + break; + case 0x30: + $tag = "octetString"; + break; + case 0x31: + $tag = "datetime"; + break; + case 0x32: + $tag = "resolution"; + break; + case 0x33: + $tag = "rangeOfInteger"; + break; + case 0x34: //RFC3382 (BLIND CODE) + $tag = "begCollection"; + break; + case 0x35: + $tag = "textWithLanguage"; + break; + case 0x36: + $tag = "nameWithLanguage"; + break; + case 0x37: //RFC3382 (BLIND CODE) + $tag = "endCollection"; + break; + case 0x40: + $tag = "IETF reserved text string"; + break; + case 0x41: + $tag = "textWithoutLanguage"; + break; + case 0x42: + $tag = "nameWithoutLanguage"; + break; + case 0x43: + $tag = "IETF reserved for future"; + break; + case 0x44: + $tag = "keyword"; + break; + case 0x45: + $tag = "uri"; + break; + case 0x46: + $tag = "uriScheme"; + break; + case 0x47: + $tag = "charset"; + break; + case 0x48: + $tag = "naturalLanguage"; + break; + case 0x49: + $tag = "mimeMediaType"; + break; + case 0x4A: // RFC3382 (BLIND CODE) + $tag = "memberAttrName"; + break; + case 0x7F: + $tag = "extended type"; + break; + default: + if ($tag >= 0x14 && $tag < 0x15 && $tag > 0x17 && $tag <= 0x1f) + { + $tag = "out-of-band"; + } + elseif (0x24 <= $tag && $tag <= 0x2f) + { + $tag = "new integer type"; + } + elseif (0x38 <= $tag && $tag <= 0x3F) + { + $tag = "new octet-stream type"; + } + elseif (0x4B <= $tag && $tag <= 0x5F) + { + $tag = "new character string type"; + } + elseif ((0x60 <= $tag && $tag < 0x7f) || $tag >= 0x80 ) + { + $tag = "IETF reserved for future"; + } + else + { + $tag = sprintf("UNKNOWN: 0x%x (%u)",$tag,$tag); + } + break; + } + + return $tag; + } + + protected function _readCollection($attributes_type,$j) + { $name_length = ord($this->serveroutput->body[$this->_parsing->offset]) * 256 + ord($this->serveroutput->body[$this->_parsing->offset + 1]); - + $this->_parsing->offset += 2; - + self::_putDebug( "Collection name_length ". $name_length ."\n"); - + $name = ''; - for ($i = 0; $i < $name_length; $i++) { + for ($i = 0; $i < $name_length; $i++) + { $name .= $this->serveroutput->body[$this->_parsing->offset]; $this->_parsing->offset += 1; if ($this->_parsing->offset > strlen($this->serveroutput->body)) + { return; } - + } + $collection_name = $name; - + $name_length = ord($this->serveroutput->body[$this->_parsing->offset]) * 256 + ord($this->serveroutput->body[$this->_parsing->offset + 1]); $this->_parsing->offset += 2; - + self::_putDebug( "Attribute name_length ". $name_length ."\n"); - + $name = ''; - for ($i = 0; $i < $name_length; $i++) { + for ($i = 0; $i < $name_length; $i++) + { $name .= $this->serveroutput->body[$this->_parsing->offset]; $this->_parsing->offset += 1; if ($this->_parsing->offset > strlen($this->serveroutput->body)) + { return; } - + } + $attribute_name = $name; - if ($attribute_name == "") { + if ($attribute_name == "") + { $attribute_name = $this->last_attribute_name; $this->collection_key[$this->collection_depth] ++; - } else { + } + else + { $this->collection_key[$this->collection_depth] = 0; } $this->last_attribute_name = $attribute_name; - + self::_putDebug( "Attribute name ".$name."\n"); - + $tag = self::_readTag(ord($this->serveroutput->body[$this->_parsing->offset])); $this->_parsing->offset ++; - + $type = $tag; - + $name_length = ord($this->serveroutput->body[$this->_parsing->offset]) * 256 + ord($this->serveroutput->body[$this->_parsing->offset + 1]); $this->_parsing->offset += 2; - + self::_putDebug( "Collection2 name_length ". $name_length ."\n"); - + $name = ''; - for ($i = 0; $i < $name_length; $i++) { + for ($i = 0; $i < $name_length; $i++) + { $name .= $this->serveroutput->body[$this->_parsing->offset]; $this->_parsing->offset += 1; if ($this->_parsing->offset > strlen($this->serveroutput->body)) + { return; } - + } + $collection_value = $name; $value_length = ord($this->serveroutput->body[$this->_parsing->offset]) * 256 + ord($this->serveroutput->body[$this->_parsing->offset + 1]); - + self::_putDebug( "Collection value_length ".$this->serveroutput->body[ $this->_parsing->offset] . $this->serveroutput->body[$this->_parsing->offset + 1] .": " . $value_length . " "); - + $this->_parsing->offset += 2; - + $value = ''; - for ($i = 0; $i < $value_length; $i++) { - + for ($i = 0; $i < $value_length; $i++) + { if ($this->_parsing->offset >= strlen($this->serveroutput->body)) + { return; + } $value .= $this->serveroutput->body[$this->_parsing->offset]; $this->_parsing->offset += 1; - - } - + } + $object = &$this->collection; - for ($i = 0 ; $i <= $this->collection_depth ; $i ++) { + for ($i = 0 ; $i <= $this->collection_depth ; $i ++) + { $indice = "_indice".$this->collection_nbr[$i]; if (!isset($object->$indice)) + { $object->$indice = (object) 'indice'; - $object = &$object->$indice; } - + $object = &$object->$indice; + } + $value_key = "_value".$this->collection_key[$this->collection_depth]; $col_name_key = "_collection_name".$this->collection_key[$this->collection_depth]; $col_val_key = "_collection_value".$this->collection_key[$this->collection_depth]; - + $attribute_value = self::_interpretAttribute($attribute_name,$tag,$value); $attribute_name = str_replace('-','_',$attribute_name); - - + self::_putDebug( sprintf("Value: %s\n",$value)); $object->$attribute_name->_type = $type; $object->$attribute_name->$value_key = $attribute_value; $object->$attribute_name->$col_name_key = $collection_name; $object->$attribute_name->$col_val_key = $collection_value; - - $this->serveroutput->response[$attributes_type][$j]['value'] = $this->collection; - } - // }}} - - // {{{ _readAttributeName ($attributes_type,$j) - protected function _readAttributeName ($attributes_type,$j,$write=1) { + $this->serveroutput->response[$attributes_type][$j]['value'] = $this->collection; + } + + protected function _readAttributeName ($attributes_type,$j,$write=1) + { $name_length = ord($this->serveroutput->body[ $this->_parsing->offset]) * 256 + ord($this->serveroutput->body[$this->_parsing->offset + 1]); $this->_parsing->offset += 2; - + self::_putDebug( "name_length ". $name_length ."\n"); - + $name = ''; - for ($i = 0; $i < $name_length; $i++) { + for ($i = 0; $i < $name_length; $i++) + { if ($this->_parsing->offset >= strlen($this->serveroutput->body)) + { return; + } $name .= $this->serveroutput->body[$this->_parsing->offset]; $this->_parsing->offset += 1; - } - + } + if($write) - $this->serveroutput->response[$attributes_type][$j]['name'] = $name; + { + $this->serveroutput->response[$attributes_type][$j]['name'] = $name; + } self::_putDebug( "name " . $name . "\n"); - - return $name; + + return $name; } - // }}} - - // {{{ _readValue ($type,$attributes_type,$j) - protected function _readValue ($type,$attributes_type,$j,$write=1) { + protected function _readValue ($type,$attributes_type,$j,$write=1) + { $value_length = ord($this->serveroutput->body[$this->_parsing->offset]) * 256 + ord($this->serveroutput->body[$this->_parsing->offset + 1]); @@ -1219,116 +1342,130 @@ class PrintIPP extends BasicIPP { .": " . $value_length . " "); - + $this->_parsing->offset += 2; - + $value = ''; - for ($i = 0; $i < $value_length; $i++) { - + for ($i = 0; $i < $value_length; $i++) + { if ($this->_parsing->offset >= strlen($this->serveroutput->body)) + { return; + } $value .= $this->serveroutput->body[$this->_parsing->offset]; $this->_parsing->offset += 1; - } - + self::_putDebug( sprintf("Value: %s\n",$value)); - + if ($write) - $this->serveroutput->response[$attributes_type][$j]['value'] = $value; + { + $this->serveroutput->response[$attributes_type][$j]['value'] = $value; + } - return $value; + return $value; } - // }}} - // {{{ _parseAttributes() - protected function _parseAttributes() { - + protected function _parseAttributes() + { $k = -1; + $l = 0; for ($i = 0 ; $i < count($this->serveroutput->response) ; $i++) + { for ($j = 0 ; $j < (count($this->serveroutput->response[$i]) - 1) ; $j ++) - if (!empty($this->serveroutput->response[$i][$j]['name'])) { + { + if (!empty($this->serveroutput->response[$i][$j]['name'])) + { $k++; $l = 0; $this->parsed[$k]['range'] = $this->serveroutput->response[$i]['attributes']; $this->parsed[$k]['name'] = $this->serveroutput->response[$i][$j]['name']; $this->parsed[$k]['type'] = $this->serveroutput->response[$i][$j]['type']; $this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value']; - } else { + } + else + { $l ++; $this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value']; - } + } + } + } $this->serveroutput->response = array(); - $this->attributes = new stdClass(); - for ($i = 0 ; $i < count($this->parsed) ; $i ++) { + $this->attributes = new \stdClass(); + for ($i = 0 ; $i < count($this->parsed) ; $i ++) + { $name = $this->parsed[$i]['name']; $php_name = str_replace('-','_',$name); $type = $this->parsed[$i]['type']; $range = $this->parsed[$i]['range']; - $this->attributes->$php_name = new stdClass(); + $this->attributes->$php_name = new \stdClass(); $this->attributes->$php_name->_type = $type; $this->attributes->$php_name->_range = $range; - for ($j = 0 ; $j < (count($this->parsed[$i]) - 3) ; $j ++) { + for ($j = 0 ; $j < (count($this->parsed[$i]) - 3) ; $j ++) + { $value = $this->parsed[$i][$j]; $index = '_value'.$j; $this->attributes->$php_name->$index = $value; } } - + $this->parsed = array(); - } - // }}} - - // {{{ _parseJobAttributes() - protected function _parseJobAttributes() { + protected function _parseJobAttributes() + { //if (!preg_match('#successful#',$this->serveroutput->status)) // return false; - $k = -1; + $l = 0; for ($i = 0 ; $i < count($this->serveroutput->response) ; $i++) + { for ($j = 0 ; $j < (count($this->serveroutput->response[$i]) - 1) ; $j ++) - if (!empty($this->serveroutput->response[$i][$j]['name'])) { + { + if (!empty($this->serveroutput->response[$i][$j]['name'])) + { $k++; $l = 0; $this->parsed[$k]['range'] = $this->serveroutput->response[$i]['attributes']; $this->parsed[$k]['name'] = $this->serveroutput->response[$i][$j]['name']; $this->parsed[$k]['type'] = $this->serveroutput->response[$i][$j]['type']; $this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value']; - } else { + } + else + { $l ++; $this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value']; - } - + } + } + } + $this->serveroutput->response = array(); - - $this->job_attributes = new stdClass(); - for ($i = 0 ; $i < count($this->parsed) ; $i ++) { + + $this->job_attributes = new \stdClass(); + for ($i = 0 ; $i < count($this->parsed) ; $i ++) + { $name = $this->parsed[$i]['name']; $php_name = str_replace('-','_',$name); $type = $this->parsed[$i]['type']; $range = $this->parsed[$i]['range']; - $this->job_attributes->$php_name = new stdClass(); + $this->job_attributes->$php_name = new \stdClass(); $this->job_attributes->$php_name->_type = $type; $this->job_attributes->$php_name->_range = $range; - for ($j = 0 ; $j < (count($this->parsed[$i]) - 3) ; $j ++) { + for ($j = 0 ; $j < (count($this->parsed[$i]) - 3) ; $j ++) + { $value = $this->parsed[$i][$j]; $index = '_value'.$j; $this->job_attributes->$php_name->$index = $value; } } - - $this->parsed = array(); - - - } - // }}} - // {{{ _interpretAttribute($attribute_name,$type,$value) - protected function _interpretAttribute($attribute_name,$type,$value) { - - switch ($type) { + $this->parsed = array(); + } + + protected function _interpretAttribute($attribute_name,$type,$value) + { + switch ($type) + { case "integer": $value = self::_interpretInteger($value); break; @@ -1338,9 +1475,13 @@ class PrintIPP extends BasicIPP { case 'boolean': $value = ord($value); if ($value == 0x00) + { $value = 'false'; + } else + { $value = 'true'; + } break; case 'datetime': $value = self::_interpretDateTime($value); @@ -1351,7 +1492,8 @@ class PrintIPP extends BasicIPP { case 'resolution': $unit = $value[8]; $value = self::_interpretRangeOfInteger(substr($value,0,8)); - switch($unit) { + switch($unit) + { case chr(0x03): $unit = "dpi"; break; @@ -1363,31 +1505,27 @@ class PrintIPP extends BasicIPP { break; default: break; - } - return $value; + } + return $value; } - // }}} - - // {{{ _interpretRangeOfInteger($value) - protected function _interpretRangeOfInteger($value) { - + + protected function _interpretRangeOfInteger($value) + { $value_parsed = 0; $integer1 = $integer2 = 0; - + $halfsize = strlen($value) / 2; - + $integer1 = self::_interpretInteger(substr($value,0,$halfsize)); $integer2 = self::_interpretInteger(substr($value,$halfsize,$halfsize)); - + $value_parsed = sprintf('%s-%s',$integer1,$integer2); - - - return $value_parsed; + + return $value_parsed; } - // }}} - - // {{{ _interpretDateTime($date) { - protected function _interpretDateTime($date) { + + protected function _interpretDateTime($date) + { $year = self::_interpretInteger(substr($date,0,2)); $month = self::_interpretInteger(substr($date,2,1)); $day = self::_interpretInteger(substr($date,3,1)); @@ -1397,21 +1535,21 @@ class PrintIPP extends BasicIPP { $direction = substr($date,8,1); $hours_from_utc = self::_interpretInteger(substr($date,9,1)); $minutes_from_utc = self::_interpretInteger(substr($date,10,1)); - + $date = sprintf('%s-%s-%s %s:%s:%s %s%s:%s',$year,$month,$day,$hour,$minute,$second,$direction,$hours_from_utc,$minutes_from_utc); - return $date; - } - // }}} - - // {{{ _interpretEnum() - protected function _interpretEnum($attribute_name,$value) { - + return $date; + } + + protected function _interpretEnum($attribute_name,$value) + { $value_parsed = self::_interpretInteger($value); - - switch ($attribute_name) { + + switch ($attribute_name) + { case 'job-state': - switch ($value_parsed) { + switch ($value_parsed) + { case 0x03: $value = 'pending'; break; @@ -1433,14 +1571,17 @@ class PrintIPP extends BasicIPP { case 0x09: $value = 'completed'; break; - } + } if ($value_parsed > 0x09) + { $value = sprintf('Unknown(IETF standards track "job-state" reserved): 0x%x',$value_parsed); + } break; case 'print-quality': case 'print-quality-supported': case 'print-quality-default': - switch ($value_parsed) { + switch ($value_parsed) + { case 0x03: $value = 'draft'; break; @@ -1453,7 +1594,8 @@ class PrintIPP extends BasicIPP { } break; case 'printer-state': - switch ($value_parsed) { + switch ($value_parsed) + { case 0x03: $value = 'idle'; break; @@ -1463,13 +1605,16 @@ class PrintIPP extends BasicIPP { case 0x05: $value = 'stopped'; break; - } + } if ($value_parsed > 0x05) + { $value = sprintf('Unknown(IETF standards track "printer-state" reserved): 0x%x',$value_parsed); + } break; - + case 'operations-supported': - switch($value_parsed) { + switch($value_parsed) + { case 0x0000: case 0x0001: $value = sprintf('Unknown(reserved) : %s',ord($value)); @@ -1602,20 +1747,31 @@ class PrintIPP extends BasicIPP { break; } if ($value_parsed > 0x002B && $value_parsed <= 0x3FFF) + { $value = sprintf('Unknown(IETF standards track operations reserved): 0x%x',$value_parsed); - elseif ($value_parsed >= 0x4000 && $value_parsed <= 0x8FFF) { - if (method_exists($this,'_getEnumVendorExtensions')) { + } + elseif ($value_parsed >= 0x4000 && $value_parsed <= 0x8FFF) + { + if (method_exists($this,'_getEnumVendorExtensions')) + { $value = $this->_getEnumVendorExtensions($value_parsed); - } else + } + else + { $value = sprintf('Unknown(Vendor extension for operations): 0x%x',$value_parsed); - } elseif ($value_parsed > 0x8FFF) + } + } + elseif ($value_parsed > 0x8FFF) + { $value = sprintf('Unknown operation (should not exists): 0x%x',$value_parsed); - + } + break; case 'finishings': case 'finishings-default': case 'finishings-supported': - switch ($value_parsed) { + switch ($value_parsed) + { case 3: $value = 'none'; break; @@ -1673,15 +1829,18 @@ class PrintIPP extends BasicIPP { case 31: $value = 'staple-dual-bottom'; break; - } + } if ($value_parsed > 31) + { $value = sprintf('Unknown(IETF standards track "finishing" reserved): 0x%x',$value_parsed); + } break; - + case 'orientation-requested': case 'orientation-requested-supported': case 'orientation-requested-default': - switch ($value_parsed) { + switch ($value_parsed) + { case 0x03: $value = 'portrait'; break; @@ -1694,77 +1853,87 @@ class PrintIPP extends BasicIPP { case 0x06: $value = 'reverse-portrait'; break; - } + } if ($value_parsed > 0x06) + { $value = sprintf('Unknown(IETF standards track "orientation" reserved): 0x%x',$value_parsed); + } break; - + default: break; - } - return $value; + } + return $value; } - // }}} - - // {{{ _getJobId () - protected function _getJobId () { - + + protected function _getJobId () + { if (!isset($this->serveroutput->response)) + { $this->jobs = array_merge($this->jobs,array('NO JOB')); - + } + $jobfinded = false; for ($i = 0 ; (!$jobfinded && array_key_exists($i,$this->serveroutput->response)) ; $i ++) + { if (($this->serveroutput->response[$i]['attributes']) == "job-attributes") + { for ($j = 0 ; array_key_exists($j,$this->serveroutput->response[$i]) ; $j++) - if ($this->serveroutput->response[$i][$j]['name'] == "job-id") { + { + if ($this->serveroutput->response[$i][$j]['name'] == "job-id") + { $this->last_job = $this->serveroutput->response[$i][$j]['value']; $this->jobs = array_merge($this->jobs,array($this->serveroutput->response[$i][$j]['value'])); return; - - } - + } + } + } + } } - // }}} - - // {{{ _getJobUri () - protected function _getJobUri () { + protected function _getJobUri () + { if (!isset($this->jobs_uri)) + { $this->jobs_uri = array(); - + } + $jobfinded = false; for ($i = 0 ; (!$jobfinded && array_key_exists($i,$this->serveroutput->response)) ; $i ++) + { if (($this->serveroutput->response[$i]['attributes']) == "job-attributes") + { for ($j = 0 ; array_key_exists($j,$this->serveroutput->response[$i]) ; $j++) - if ($this->serveroutput->response[$i][$j]['name'] == "job-uri") { + { + if ($this->serveroutput->response[$i][$j]['name'] == "job-uri") + { $this->last_job = $this->serveroutput->response[$i][$j]['value']; $this->jobs_uri = array_merge($this->jobs_uri,array($this->last_job)); return; - - } + } + } + } + } $this->last_job = ''; - } - // }}} - - // {{{ _parseResponse () - protected function _parseResponse () { + + protected function _parseResponse () + { $j = -1; $this->index = 0; - for ($i = $this->_parsing->offset; $i < strlen($this->serveroutput->body) ; $i = $this->_parsing->offset) { - - + for ($i = $this->_parsing->offset; $i < strlen($this->serveroutput->body) ; $i = $this->_parsing->offset) + { $tag = ord($this->serveroutput->body[$this->_parsing->offset]); - - - if ($tag > 0x0F) { - + + if ($tag > 0x0F) + { self::_readAttribute($j); $this->index ++; continue; - } + } - switch ($tag) { + switch ($tag) + { case 0x01: $j += 1; $this->serveroutput->response[$j]['attributes'] = "operation-attributes"; @@ -1782,7 +1951,9 @@ class PrintIPP extends BasicIPP { $this->serveroutput->response[$j]['attributes'] = "end-of-attributes"; self::_putDebug( "tag is: ".$this->serveroutput->response[$j]['attributes']."\n"); if ($this->alert_on_end_tag === 1) + { echo "END tag OK
"; + } $this->response_completed[(count($this->response_completed) -1)] = "completed"; return; case 0x04: @@ -1803,21 +1974,16 @@ class PrintIPP extends BasicIPP { $this->index = 0; $this->_parsing->offset += 1; break; - } - - self::_putDebug( "tag is: ".$this->serveroutput->response[$j]['attributes']."\n\n\n"); - - } - return; + } + + self::_putDebug( "tag is: ".$this->serveroutput->response[$j]['attributes']."\n\n\n"); + } + return; } - // }}} - - - /* // NOTICE : HAVE TO READ AGAIN RFC 2911 TO SEE IF IT IS PART OF SERVER'S RESPONSE (CUPS DO NOT) - // {{{ _getPrinterUri () + protected function _getPrinterUri () { for ($i = 0 ; (array_key_exists($i,$this->serveroutput->response)) ; $i ++) @@ -1833,32 +1999,43 @@ class PrintIPP extends BasicIPP { $this->printers_uri = array_merge($this->printers_uri,array('')); } - // }}} + */ -// REQUEST BUILDING - - // {{{ _stringCancel () - protected function _stringCancel ($job_uri) { + // REQUEST BUILDING + protected function _stringCancel ($job_uri) + { if (!isset($this->setup->charset)) - self::setCharset('us-ascii'); + { + self::setCharset(); + } if (!isset($this->setup->datatype)) + { self::setBinary(); + } if (!isset($this->setup->language)) + { self::setLanguage('en_us'); + } if (!$this->requesting_user) + { self::setUserName(); + } if (!isset($this->meta->message)) + { $this->meta->message = ''; + } self::_setOperationId(); - + self::_setJobUri($job_uri); - + if (!isset($this->error_generation->request_body_malformed)) + { $this->error_generation->request_body_malformed = ""; - + } + $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number . chr(0x00) . chr (0x08) // cancel-Job | operation-id . $this->meta->operation_id // request-id @@ -1874,16 +2051,4 @@ class PrintIPP extends BasicIPP { self::_putDebug( sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob)); return TRUE; } - // }}} - - -}; - -/* - * Local variables: - * mode: php - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ -?> +} diff --git a/htdocs/includes/printipp/http_class.php b/htdocs/includes/printipp/http_class.php index 569d4f6648f..30bb33d663b 100644 --- a/htdocs/includes/printipp/http_class.php +++ b/htdocs/includes/printipp/http_class.php @@ -29,7 +29,7 @@ */ /** * This class is intended to implement a subset of Hyper Text Transfer Protocol - * (HTTP/1.1) on client side  (currently: POST operation), with file streaming + * (HTTP/1.1) on client side (currently: POST operation), with file streaming * capability. * * It can perform Basic and Digest authentication. @@ -66,48 +66,58 @@ ************************/ class httpException extends Exception { - protected $errno; - public function __construct ($msg, $errno = null) - { - parent::__construct ($msg); - $this->errno = $errno; - } - public function getErrorFormatted () - { - return sprintf ("[http_class]: %s -- "._(" file %s, line %s"), - $this->getMessage (), $this->getFile (), $this->getLine ()); - } - public function getErrno () - { - return $this->errno; - } + protected $errno; + + public function __construct ($msg, $errno = null) + { + parent::__construct ($msg); + $this->errno = $errno; + } + + public function getErrorFormatted () + { + return sprintf ("[http_class]: %s -- "._(" file %s, line %s"), + $this->getMessage (), $this->getFile (), $this->getLine ()); + } + + public function getErrno () + { + return $this->errno; + } } function error2string($value) { - $level_names = array( - E_ERROR => 'E_ERROR', - E_WARNING => 'E_WARNING', - E_PARSE => 'E_PARSE', - E_NOTICE => 'E_NOTICE', - E_CORE_ERROR => 'E_CORE_ERROR', - E_CORE_WARNING => 'E_CORE_WARNING', - E_COMPILE_ERROR => 'E_COMPILE_ERROR', - E_COMPILE_WARNING => 'E_COMPILE_WARNING', - E_USER_ERROR => 'E_USER_ERROR', - E_USER_WARNING => 'E_USER_WARNING', - E_USER_NOTICE => 'E_USER_NOTICE' - ); - if(defined('E_STRICT')) $level_names[E_STRICT]='E_STRICT'; - $levels=array(); - if(($value&E_ALL)==E_ALL) - { - $levels[]='E_ALL'; - $value&=~E_ALL; - } - foreach($level_names as $level=>$name) - if(($value&$level)==$level) $levels[]=$name; - return implode(' | ',$levels); + $level_names = array( + E_ERROR => 'E_ERROR', + E_WARNING => 'E_WARNING', + E_PARSE => 'E_PARSE', + E_NOTICE => 'E_NOTICE', + E_CORE_ERROR => 'E_CORE_ERROR', + E_CORE_WARNING => 'E_CORE_WARNING', + E_COMPILE_ERROR => 'E_COMPILE_ERROR', + E_COMPILE_WARNING => 'E_COMPILE_WARNING', + E_USER_ERROR => 'E_USER_ERROR', + E_USER_WARNING => 'E_USER_WARNING', + E_USER_NOTICE => 'E_USER_NOTICE' + ); + if(defined('E_STRICT')) { + $level_names[E_STRICT]='E_STRICT'; + } + $levels=array(); + if(($value&E_ALL)==E_ALL) + { + $levels[]='E_ALL'; + $value&=~E_ALL; + } + foreach($level_names as $level=>$name) + { + if(($value&$level)==$level) + { + $levels[]=$name; + } + } + return implode(' | ',$levels); } /*********************** @@ -117,499 +127,486 @@ function error2string($value) ************************/ class http_class { - // variables declaration - public $debug; - public $html_debug; - public $timeout = 30; // time waiting for connection, seconds - public $data_timeout = 30; // time waiting for data, milliseconds - public $data_chunk_timeout = 1; // time waiting between data chunks, millisecond - public $force_multipart_form_post; - public $username; - public $password; - public $request_headers = array (); - public $request_body = "Not a useful information"; - public $status; - public $window_size = 1024; // chunk size of data - public $with_exceptions = 0; // compatibility mode for old scripts - public $port; - public $host; - private $default_port = 631; - private $headers; - private $reply_headers = array (); - private $reply_body = array (); - private $connection; - private $arguments; - private $bodystream = array (); - private $last_limit; - private $connected; - private $nc = 1; - private $user_agent = "PRINTIPP/0.81+CVS"; - private $readed_bytes = 0; + // variables declaration + public $debug; + public $html_debug; + public $timeout = 30; // time waiting for connection, seconds + public $data_timeout = 30; // time waiting for data, milliseconds + public $data_chunk_timeout = 1; // time waiting between data chunks, millisecond + public $force_multipart_form_post; + public $username; + public $password; + public $request_headers = array (); + public $request_body = "Not a useful information"; + public $status; + public $window_size = 1024; // chunk size of data + public $with_exceptions = 0; // compatibility mode for old scripts + public $port; + public $host; + private $default_port = 631; + private $headers; + private $reply_headers = array (); + private $reply_body = array (); + private $connection; + private $arguments; + private $bodystream = array (); + private $last_limit; + private $connected; + private $nc = 1; + private $user_agent = "PRINTIPP/0.81+CVS"; + private $readed_bytes = 0; - public function __construct () - { - true; - } - - /********************* - * - * Public functions - * - **********************/ - - public function GetRequestArguments ($url, &$arguments) - { - $this->arguments = array (); - $arguments["URL"] = $this->arguments["URL"] = $url; - $arguments["RequestMethod"] = $this->arguments["RequestMethod"] = "POST"; - $this->headers["Content-Length"] = 0; - $this->headers["Content-Type"] = "application/octet-stream"; - $this->headers["Host"] = $this->host; - $this->headers["User-Agent"] = $this->user_agent; - //$this->headers["Expect"] = "100-continue"; - - } - - public function Open ($arguments) - { - $this->connected = false; - $url = $arguments["URL"]; - $port = $this->default_port; - #$url = split (':', $url, 2); - $url = preg_split ('#:#', $url, 2); - $transport_type = $url[0]; - $unix = false; - switch ($transport_type) - { - case 'http': - $transport_type = 'tcp://'; - break; - - case 'https': - $transport_type = 'tls://'; - break; - - case 'unix': - $transport_type = 'unix://'; - $port = 0; - $unix = true; - break; - - default: - $transport_type = 'tcp://'; - break; - } - $url = $url[1]; - if (!$unix) - { - #$url = split ("/", preg_replace ("#^/{1,}#", '', $url), 2); - $url = preg_split ("#/#", preg_replace ("#^/{1,}#", '', $url), 2); - $url = $url[0]; - $port = $this->port; - $error = sprintf (_("Cannot resolve url: %s"), $url); - $ip = gethostbyname ($url); - $ip = @gethostbyaddr ($ip); - if (!$ip) - { - return $this->_HttpError ($error, E_USER_WARNING); - } - if (strstr ($url, ":")) // we got an ipv6 address - if (!strstr ($url, "[")) // it is not escaped - $url = sprintf ("[%s]", $url); - } - $this->connection = @fsockopen ($transport_type.$url, $port, $errno, $errstr, $this->timeout); - $error = - sprintf (_('Unable to connect to "%s%s port %s": %s'), $transport_type, - $url, $port, $errstr); - if (!$this->connection) - { - return $this->_HttpError ($error, E_USER_WARNING); - } - $this->connected = true; - return array (true, "success"); - } - - public function SendRequest ($arguments) - { - $error = - sprintf (_('Streaming request failed to %s'), $arguments['RequestURI']); - $result = self::_StreamRequest ($arguments); - if (!$result[0]) - { - return $this->_HttpError ($error." ".$result[1], E_USER_WARNING); - } - self::_ReadReply (); - if (!preg_match ('#http/1.1 401 unauthorized#', $this->status)) - { - return array (true, "success"); - } - $headers = array_keys ($this->reply_headers); - $error = _("need authentication but no mechanism provided"); - if (!in_array ("www-authenticate", $headers)) - { - return $this->_HttpError ($error, E_USER_WARNING); - } - #$authtype = split (' ', $this->reply_headers["www-authenticate"]); - $authtype = preg_split ('# #', $this->reply_headers["www-authenticate"]); - $authtype = strtolower ($authtype[0]); - switch ($authtype) - { - case 'basic': - $pass = base64_encode ($this->user.":".$this->password); - $arguments["Headers"]["Authorization"] = "Basic ".$pass; - break; - - case 'digest': - $arguments["Headers"]["Authorization"] = self::_BuildDigest (); - break; - - default: - $error = - sprintf (_("need '%s' authentication mechanism, but have not"), - $authtype[0]); - return $this->_HttpError ($error, E_USER_WARNING); - break; - - } - self::Close (); - self::Open ($arguments); - $error = - sprintf (_ - ('Streaming request failed to %s after a try to authenticate'), - $url); - $result = self::_StreamRequest ($arguments); - if (!$result[0]) - { - return $this->_HttpError ($error.": ".$result[1], E_USER_WARNING); - } - self::_ReadReply (); - return array (true, "success"); - } - - public function ReadReplyHeaders (&$headers) - { - $headers = $this->reply_headers; - } - - public function ReadReplyBody (&$body, $chunk_size) - { - $body = substr ($this->reply_body, $this->last_limit, $chunk_size); - $this->last_limit += $chunk_size; - } - - public function Close () - { - if (!$this->connected) - return; - fclose ($this->connection); - } - - /********************* - * - * Private functions - * - *********************/ - - private function _HttpError ($msg, $level, $errno = null) - { - $trace = ''; - $backtrace = debug_backtrace; - foreach ($backtrace as $trace) - { - $trace .= sprintf ("in [file: '%s'][function: '%s'][line: %s];\n", $trace['file'], $trace['function'],$trace['line']); - } - $msg = sprintf ( '%s\n%s: [errno: %s]: %s', - $trace, error2string ($level), $errno, $msg); - if ($this->with_exceptions) - { - throw new httpException ($msg, $errno); - } - else - { - trigger_error ($msg, $level); - return array (false, $msg); - } - } - - private function _streamString ($string) - { - $success = fwrite ($this->connection, $string); - if (!$success) - { - return false; - } - return true; - } - - private function _StreamRequest ($arguments) - { - $this->status = false; - $this->reply_headers = array (); - $this->reply_body = ""; - if (!$this->connected) - { - return _HttpError (_("not connected"), E_USER_WARNING); - } - $this->arguments = $arguments; - $content_length = 0; - foreach ($this->arguments["BodyStream"] as $argument) - { - list ($type, $value) = each ($argument); - reset ($argument); - if ($type == "Data") - { - $length = strlen ($value); - } - elseif ($type == "File") - { - if (is_readable ($value)) + public function __construct () { - $length = filesize ($value); + true; } - else + + /********************* + * + * Public functions + * + **********************/ + + public function GetRequestArguments ($url, &$arguments) { - $length = 0; - return - _HttpError (sprintf (_("%s: file is not readable"), $value), - E_USER_WARNING); + $this->arguments = array (); + $this->arguments["URL"] = $arguments["URL"] = $url; + $this->arguments["RequestMethod"] = $arguments["RequestMethod"] = "POST"; + $this->headers["Content-Length"] = 0; + $this->headers["Content-Type"] = "application/octet-stream"; + $this->headers["Host"] = $this->host; + $this->headers["User-Agent"] = $this->user_agent; + //$this->headers["Expect"] = "100-continue"; } - } - else - { - $length = 0; - return - _HttpError (sprintf - (_("%s: not a valid argument for content"), $type), - E_USER_WARNING); - } - $content_length += $length; - } - $this->request_body = sprintf (_("%s Bytes"), $content_length); - $this->headers["Content-Length"] = $content_length; - $this->arguments["Headers"] = - array_merge ($this->headers, $this->arguments["Headers"]); - if ($this->arguments["RequestMethod"] != "POST") - { - return - _HttpError (sprintf - (_("%s: method not implemented"), - $arguments["RequestMethod"]), E_USER_WARNING); - } - $string = - sprintf ("POST %s HTTP/1.1\r\n", $this->arguments["RequestURI"]); - $this->request_headers[$string] = ''; - if (!$this->_streamString ($string)) - { - return _HttpError (_("Error while puts POST operation"), - E_USER_WARNING); - } - foreach ($this->arguments["Headers"] as $header => $value) - { - $string = sprintf ("%s: %s\r\n", $header, $value); - $this->request_headers[$header] = $value; - if (!$this->_streamString ($string)) - { - return _HttpError (_("Error while puts HTTP headers"), - E_USER_WARNING); - } - } - $string = "\r\n"; - if (!$this->_streamString ($string)) - { - return _HttpError (_("Error while ends HTTP headers"), - E_USER_WARNING); - } - foreach ($this->arguments["BodyStream"] as $argument) - { - list ($type, $value) = each ($argument); - reset ($argument); - if ($type == "Data") - { - $streamed_length = 0; - while ($streamed_length < strlen ($value)) + + public function Open ($arguments) { - $string = substr ($value, $streamed_length, $this->window_size); - if (!$this->_streamString ($string)) - { - return _HttpError (_("error while sending body data"), - E_USER_WARNING); - } - $streamed_length += $this->window_size; + $this->connected = false; + $url = $arguments["URL"]; + $port = $this->default_port; + #$url = split (':', $url, 2); + $url = preg_split ('#:#', $url, 2); + $transport_type = $url[0]; + $unix = false; + switch ($transport_type) + { + case 'http': + $transport_type = 'tcp://'; + break; + + case 'https': + $transport_type = 'tls://'; + break; + + case 'unix': + $transport_type = 'unix://'; + $port = 0; + $unix = true; + break; + + default: + $transport_type = 'tcp://'; + break; + } + $url = $url[1]; + if (!$unix) + { + #$url = split ("/", preg_replace ("#^/{1,}#", '', $url), 2); + $url = preg_split ("#/#", preg_replace ("#^/{1,}#", '', $url), 2); + $url = $url[0]; + $port = $this->port; + $error = sprintf (_("Cannot resolve url: %s"), $url); + $ip = gethostbyname ($url); + $ip = @gethostbyaddr ($ip); + if (!$ip) + { + return $this->_HttpError ($error, E_USER_WARNING); + } + if (strstr ($url, ":")) // we got an ipv6 address + { + if (!strstr ($url, "[")) // it is not escaped + { + $url = sprintf ("[%s]", $url); + } + } + } + $this->connection = @fsockopen ($transport_type.$url, $port, $errno, $errstr, $this->timeout); + $error = + sprintf (_('Unable to connect to "%s%s port %s": %s'), $transport_type, + $url, $port, $errstr); + if (!$this->connection) + { + return $this->_HttpError ($error, E_USER_WARNING); + } + $this->connected = true; + return array (true, "success"); } - } - elseif ($type == "File") - { - if (is_readable ($value)) + + public function SendRequest ($arguments) { - $file = fopen ($value, 'rb'); - while (!feof ($file)) - { - if (gettype ($block = @fread ($file, $this->window_size)) != - "string") - { - return _HttpError (_("cannot read file to upload"), - E_USER_WARNING); - } - if (!$this->_streamString ($block)) - { - return _HttpError (_("error while sending body data"), - E_USER_WARNING); - } - } + $error = + sprintf (_('Streaming request failed to %s'), $arguments['RequestURI']); + $result = self::_StreamRequest ($arguments); + if (!$result[0]) + { + return $this->_HttpError ($error." ".$result[1], E_USER_WARNING); + } + self::_ReadReply (); + if (!preg_match ('#http/1.1 401 unauthorized#', $this->status)) + { + return array (true, "success"); + } + $headers = array_keys ($this->reply_headers); + $error = _("need authentication but no mechanism provided"); + if (!in_array ("www-authenticate", $headers)) + { + return $this->_HttpError ($error, E_USER_WARNING); + } + #$authtype = split (' ', $this->reply_headers["www-authenticate"]); + $authtype = preg_split ('# #', $this->reply_headers["www-authenticate"]); + $authtype = strtolower ($authtype[0]); + switch ($authtype) + { + case 'basic': + $pass = base64_encode ($this->user.":".$this->password); + $arguments["Headers"]["Authorization"] = "Basic ".$pass; + break; + + case 'digest': + $arguments["Headers"]["Authorization"] = self::_BuildDigest (); + break; + + default: + $error = + sprintf (_("need '%s' authentication mechanism, but have not"), + $authtype[0]); + return $this->_HttpError ($error, E_USER_WARNING); + break; + } + self::Close (); + self::Open ($arguments); + + $error = sprintf(_('Streaming request failed to %s after a try to authenticate'), $arguments['RequestURI']); + $result = self::_StreamRequest ($arguments); + if (!$result[0]) + { + return $this->_HttpError ($error.": ".$result[1], E_USER_WARNING); + } + self::_ReadReply (); + return array (true, "success"); } - } - } - return array (true, "success"); - } - private function _ReadReply () - { - if (!$this->connected) - { - return array (false, _("not connected")); - } - $this->reply_headers = array (); - $this->reply_body = ""; - $headers = array (); - $body = ""; - while (!feof ($this->connection)) - { - $line = fgets ($this->connection, 1024); - if (strlen (trim($line)) == 0) - break; // \r\n => end of headers - if (preg_match ('#^[[:space:]]#', $line)) - { - $headers[-1] .= sprintf(' %s', trim ($line)); - continue; - } - $headers[] = trim ($line); - } - $this->status = isset ($headers[0]) ? strtolower ($headers[0]) : false; - foreach ($headers as $header) - { - $header = preg_split ("#: #", $header); - $header[0] = strtolower ($header[0]); - if ($header[0] !== "www-authenticate") - { - $header[1] = isset ($header[1]) ? strtolower ($header[1]) : ""; - } - if (!isset ($this->reply_headers[$header[0]])) - { - $this->reply_headers[$header[0]] = $header[1]; - } - } - self::_ReadStream (); - return true; - } + public function ReadReplyHeaders (&$headers) + { + $headers = $this->reply_headers; + } - private function _ReadStream () - { - if (! array_key_exists ("content-length", $this->reply_headers)) - { - stream_set_blocking($this->connection, 0); - $this->reply_body = stream_get_contents($this->connection); - return true; - } - stream_set_blocking($this->connection, 1); - $content_length = $this->reply_headers["content-length"]; - $this->reply_body = stream_get_contents($this->connection,$content_length); - return true; - } + public function ReadReplyBody (&$body, $chunk_size) + { + $body = substr ($this->reply_body, $this->last_limit, $chunk_size); + $this->last_limit += $chunk_size; + } - private function _BuildDigest () - { - $auth = $this->reply_headers["www-authenticate"]; - #list ($head, $auth) = split (" ", $auth, 2); - list ($head, $auth) = preg_split ("# #", $auth, 2); - #$auth = split (", ", $auth); - $auth = preg_split ("#, #", $auth); - foreach ($auth as $sheme) - { - #list ($sheme, $value) = split ('=', $sheme); - list ($sheme, $value) = preg_split ('#=#', $sheme); - $fields[$sheme] = trim (trim ($value), '"'); - } - $nc = sprintf ('%x', $this->nc); - $prepend = ""; - while ((strlen ($nc) + strlen ($prepend)) < 8) - $prependi .= "0"; - $nc = $prepend.$nc; - $cnonce = "printipp"; - $username = $this->user; - $password = $this->password; - $A1 = $username.":".$fields["realm"].":".$password; - if (array_key_exists ("algorithm", $fields)) - { - $algorithm = strtolower ($fields["algorithm"]); - switch ($algorithm) - { - case "md5": - break; + public function Close () + { + if (!$this->connected) + { + return; + } + fclose ($this->connection); + } - case "md5-sess": - $A1 = - $username.":".$fields["realm"].":".$password.":". - $fields['nonce'].":".$cnonce; - break; + /********************* + * + * Private functions + * + *********************/ - default: - return _HttpError( - sprintf (_("digest Authorization: algorithm '%s' not implemented"), - $algorithm), - E_USER_WARNING); - return false; - break; - } - } - $A2 = "POST:".$this->arguments["RequestURI"]; - if (array_key_exists ("qop", $fields)) - { - $qop = strtolower ($fields["qop"]); - #$qop = split (" ", $qop); - $qop = preg_split ("# #", $qop); - if (in_array ("auth", $qop)) - $qop = "auth"; - else - { - self::_HttpError( - sprintf (_("digest Authorization: algorithm '%s' not implemented"), - $qop), - E_USER_WARNING); - return false; - } - } - $response = md5 (md5 ($A1).":".$fields["nonce"].":".md5 ($A2)); - if (isset ($qop) && ($qop == "auth")) - { - $response = - md5 (md5 ($A1).":".$fields["nonce"].":".$nc.":".$cnonce.":".$qop. - ":".$A2); - } - $auth_scheme = - sprintf - ('Digest username="%s", realm="%s", nonce="%s", uri="%s", response="%s"', - $username, $fields["realm"], $fields['nonce'], - $this->arguments["RequestURI"], $response); - if (isset ($algorithm)) - $auth_scheme .= sprintf (', algorithm="%s"', $algorithm); - if (isset ($qop)) - $auth_scheme .= sprintf (', cnonce="%s"', $cnonce); - if (array_key_exists ("opaque", $fields)) - $auth_scheme .= sprintf (', opaque="%s"', $fields['opaque']); - if (isset ($qop)) - $auth_scheme .= sprintf (', qop="%s"', $qop); - $auth_scheme .= sprintf (', nc=%s', $nc); - $this->nc++; - return $auth_scheme; - } + private function _HttpError ($msg, $level, $errno = null) + { + $trace = ''; + $backtrace = debug_backtrace(); + foreach ($backtrace as $trace) + { + $trace .= sprintf ("in [file: '%s'][function: '%s'][line: %s];\n", $trace['file'], $trace['function'],$trace['line']); + } + $msg = sprintf ( '%s\n%s: [errno: %s]: %s', + $trace, error2string ($level), $errno, $msg); + if ($this->with_exceptions) + { + throw new httpException ($msg, $errno); + } + else + { + trigger_error ($msg, $level); + return array (false, $msg); + } + } -}; + private function _streamString ($string) + { + $success = fwrite ($this->connection, $string); + if (!$success) + { + return false; + } + return true; + } -/* - * Local variables: - * mode: php - * tab-width: 2 - * c-basic-offset: 2 - * End: - */ -?> + private function _StreamRequest ($arguments) + { + $this->status = false; + $this->reply_headers = array (); + $this->reply_body = ""; + if (!$this->connected) + { + return $this->_HttpError (_("not connected"), E_USER_WARNING); + } + $this->arguments = $arguments; + $content_length = 0; + foreach ($this->arguments["BodyStream"] as $argument) + { + list ($type, $value) = each ($argument); + reset ($argument); + if ($type == "Data") + { + $length = strlen ($value); + } + elseif ($type == "File") + { + if (is_readable ($value)) + { + $length = filesize ($value); + } + else + { + $length = 0; + return $this->_HttpError (sprintf (_("%s: file is not readable"), $value), E_USER_WARNING); + } + } + else + { + $length = 0; + return $this->_HttpError (sprintf(_("%s: not a valid argument for content"), $type), E_USER_WARNING); + } + $content_length += $length; + } + $this->request_body = sprintf (_("%s Bytes"), $content_length); + $this->headers["Content-Length"] = $content_length; + $this->arguments["Headers"] = array_merge ($this->headers, $this->arguments["Headers"]); + if ($this->arguments["RequestMethod"] != "POST") + { + return $this->_HttpError (sprintf(_("%s: method not implemented"), $arguments["RequestMethod"]), E_USER_WARNING); + } + $string = sprintf ("POST %s HTTP/1.1\r\n", $this->arguments["RequestURI"]); + $this->request_headers[$string] = ''; + if (!$this->_streamString ($string)) + { + return $this->_HttpError (_("Error while puts POST operation"), E_USER_WARNING); + } + foreach ($this->arguments["Headers"] as $header => $value) + { + $string = sprintf ("%s: %s\r\n", $header, $value); + $this->request_headers[$header] = $value; + if (!$this->_streamString ($string)) + { + return $this->_HttpError (_("Error while puts HTTP headers"), E_USER_WARNING); + } + } + $string = "\r\n"; + if (!$this->_streamString ($string)) + { + return $this->_HttpError (_("Error while ends HTTP headers"), E_USER_WARNING); + } + foreach ($this->arguments["BodyStream"] as $argument) + { + list ($type, $value) = each ($argument); + reset ($argument); + if ($type == "Data") + { + $streamed_length = 0; + while ($streamed_length < strlen ($value)) + { + $string = substr ($value, $streamed_length, $this->window_size); + if (!$this->_streamString ($string)) + { + return $this->_HttpError (_("error while sending body data"), E_USER_WARNING); + } + $streamed_length += $this->window_size; + } + } + elseif ($type == "File") + { + if (is_readable ($value)) + { + $file = fopen ($value, 'rb'); + while (!feof ($file)) + { + if (gettype ($block = @fread ($file, $this->window_size)) != "string") + { + return $this->_HttpError (_("cannot read file to upload"), E_USER_WARNING); + } + if (!$this->_streamString ($block)) + { + return $this->_HttpError (_("error while sending body data"), E_USER_WARNING); + } + } + } + } + } + return array (true, "success"); + } + + private function _ReadReply () + { + if (!$this->connected) + { + return array (false, _("not connected")); + } + $this->reply_headers = array (); + $this->reply_body = ""; + $headers = array (); + $body = ""; + while (!feof ($this->connection)) + { + $line = fgets ($this->connection, 1024); + if (strlen (trim($line)) == 0) + { + break; + } // \r\n => end of headers + if (preg_match ('#^[[:space:]]#', $line)) + { + $headers[-1] .= sprintf(' %s', trim ($line)); + continue; + } + $headers[] = trim ($line); + } + $this->status = isset ($headers[0]) ? strtolower ($headers[0]) : false; + foreach ($headers as $header) + { + $header = preg_split ("#: #", $header); + $header[0] = strtolower ($header[0]); + if ($header[0] !== "www-authenticate") + { + $header[1] = isset ($header[1]) ? strtolower ($header[1]) : ""; + } + if (!isset ($this->reply_headers[$header[0]])) + { + $this->reply_headers[$header[0]] = $header[1]; + } + } + self::_ReadStream (); + return true; + } + + private function _ReadStream () + { + if (! array_key_exists ("content-length", $this->reply_headers)) + { + stream_set_blocking($this->connection, 0); + $this->reply_body = stream_get_contents($this->connection); + return true; + } + stream_set_blocking($this->connection, 1); + $content_length = $this->reply_headers["content-length"]; + $this->reply_body = stream_get_contents($this->connection,$content_length); + return true; + } + + private function _BuildDigest () + { + $auth = $this->reply_headers["www-authenticate"]; + #list ($head, $auth) = split (" ", $auth, 2); + list ($head, $auth) = preg_split ("# #", $auth, 2); + #$auth = split (", ", $auth); + $auth = preg_split ("#, #", $auth); + foreach ($auth as $sheme) + { + #list ($sheme, $value) = split ('=', $sheme); + list ($sheme, $value) = preg_split ('#=#', $sheme); + $fields[$sheme] = trim (trim ($value), '"'); + } + $nc = sprintf ('%x', $this->nc); + $prepend = ""; + while ((strlen ($nc) + strlen ($prepend)) < 8) + $prependi .= "0"; + $nc = $prepend.$nc; + $cnonce = "printipp"; + $username = $this->user; + $password = $this->password; + $A1 = $username.":".$fields["realm"].":".$password; + if (array_key_exists ("algorithm", $fields)) + { + $algorithm = strtolower ($fields["algorithm"]); + switch ($algorithm) + { + case "md5": + break; + + case "md5-sess": + $A1 = + $username.":".$fields["realm"].":".$password.":". + $fields['nonce'].":".$cnonce; + break; + + default: + return $this->_HttpError( + sprintf (_("digest Authorization: algorithm '%s' not implemented"), + $algorithm), + E_USER_WARNING); + return false; + break; + } + } + $A2 = "POST:".$this->arguments["RequestURI"]; + if (array_key_exists ("qop", $fields)) + { + $qop = strtolower ($fields["qop"]); + #$qop = split (" ", $qop); + $qop = preg_split ("# #", $qop); + if (in_array ("auth", $qop)) + { + $qop = "auth"; + } + else + { + self::_HttpError( + sprintf (_("digest Authorization: algorithm '%s' not implemented"), + $qop), + E_USER_WARNING); + return false; + } + } + $response = md5 (md5 ($A1).":".$fields["nonce"].":".md5 ($A2)); + if (isset ($qop) && ($qop == "auth")) + { + $response = + md5 (md5 ($A1).":".$fields["nonce"].":".$nc.":".$cnonce.":".$qop. + ":".$A2); + } + $auth_scheme = + sprintf + ('Digest username="%s", realm="%s", nonce="%s", uri="%s", response="%s"', + $username, $fields["realm"], $fields['nonce'], + $this->arguments["RequestURI"], $response); + if (isset ($algorithm)) + { + $auth_scheme .= sprintf (', algorithm="%s"', $algorithm); + } + if (isset ($qop)) + { + $auth_scheme .= sprintf (', cnonce="%s"', $cnonce); + } + if (array_key_exists ("opaque", $fields)) + { + $auth_scheme .= sprintf (', opaque="%s"', $fields['opaque']); + } + if (isset ($qop)) + { + $auth_scheme .= sprintf (', qop="%s"', $qop); + } + $auth_scheme .= sprintf (', nc=%s', $nc); + $this->nc++; + return $auth_scheme; + } +} diff --git a/htdocs/install/mysql/data/llx_const.sql b/htdocs/install/mysql/data/llx_const.sql index 0c0a98355c0..3b627f3d99b 100644 --- a/htdocs/install/mysql/data/llx_const.sql +++ b/htdocs/install/mysql/data/llx_const.sql @@ -40,13 +40,13 @@ insert into llx_const (name, value, type, note, visible, entity) values ('SYSLOG insert into llx_const (name, value, type, note, visible, entity) values ('SYSLOG_FILE','DOL_DATA_ROOT/dolibarr.log','chaine','Directory where to write log file',0,0); insert into llx_const (name, value, type, note, visible, entity) values ('SYSLOG_LEVEL','7','chaine','Level of debug info to show',0,0); -insert into llx_const (name, value, type, note, visible, entity) values ('MAIN_MAIL_SMTP_SERVER','','chaine','Host or ip address for SMTP server',0,0); -insert into llx_const (name, value, type, note, visible, entity) values ('MAIN_MAIL_SMTP_PORT','','chaine','Port for SMTP server',0,0); - insert into llx_const (name, value, type, note, visible, entity) values ('MAIN_UPLOAD_DOC','2048','chaine','Max size for file upload (0 means no upload allowed)',0,0); -- Hidden but specific to one entity insert into llx_const (name, value, type, note, visible, entity) values ('MAIN_MONNAIE','EUR','chaine','Monnaie',0,1); + +insert into llx_const (name, value, type, note, visible, entity) values ('MAIN_MAIL_SMTP_SERVER','','chaine','Host or ip address for SMTP server',0,1); +insert into llx_const (name, value, type, note, visible, entity) values ('MAIN_MAIL_SMTP_PORT','','chaine','Port for SMTP server',0,1); insert into llx_const (name, value, type, note, visible, entity) values ('MAIN_MAIL_EMAIL_FROM','robot@domain.com','chaine','EMail emetteur pour les emails automatiques Dolibarr',0,1); -- diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql index ad05f850e16..7dbdb7eb7dc 100755 --- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql +++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql @@ -153,6 +153,9 @@ ALTER TABLE llx_projet_task_time ADD COLUMN task_datehour datetime after task_da ALTER TABLE llx_actioncomm_resources CHANGE COLUMN transparent transparency smallint default 1; +ALTER TABLE llx_actioncomm_resources DROP INDEX idx_actioncomm_resources_idx1; +ALTER TABLE llx_actioncomm_resources ADD UNIQUE INDEX uk_actioncomm_resources(fk_actioncomm, element_type, fk_element); + -- Localtaxes by thirds ALTER TABLE llx_c_tva MODIFY COLUMN localtax1 varchar(10); diff --git a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql index 755195c2a61..cb70f85a32c 100755 --- a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql +++ b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql @@ -26,7 +26,47 @@ create table llx_c_price_expression expression varchar(80) NOT NULL )ENGINE=innodb; +--create table for user conf of printing driver +CREATE TABLE llx_printing +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp, + datec datetime, + printer_name text NOT NULL, + printer_location text NOT NULL, + printer_id varchar(255) NOT NULL, + copy integer NOT NULL DEFAULT '1', + module varchar(16) NOT NULL, + driver varchar(16) NOT NULL, + userid integer +)ENGINE=innodb; + ALTER TABLE llx_product_fournisseur_price ADD fk_price_expression integer DEFAULT NULL; -- Taiwan VAT Rates insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 2131, 213, '5', '0', 'VAT 5%', 1); + +-- Add situation invoices +ALTER TABLE llx_facture ADD COLUMN situation_cycle_ref smallint; +ALTER TABLE llx_facture ADD COLUMN situation_counter smallint; +ALTER TABLE llx_facture ADD COLUMN situation_final smallint; +ALTER TABLE llx_facturedet ADD COLUMN situation_percent real; +ALTER TABLE llx_facturedet ADD COLUMN fk_prev_id integer; + +-- Convert SMTP config to main entity, so new entities don't get the old values +UPDATE llx_const SET entity = 1 WHERE entity = 0 AND name = "MAIN_MAIL_SENDMODE"; +UPDATE llx_const SET entity = 1 WHERE entity = 0 AND name = "MAIN_MAIL_SMTP_PORT"; +UPDATE llx_const SET entity = 1 WHERE entity = 0 AND name = "MAIN_MAIL_SMTP_SERVER"; +UPDATE llx_const SET entity = 1 WHERE entity = 0 AND name = "MAIN_MAIL_SMTPS_ID"; +UPDATE llx_const SET entity = 1 WHERE entity = 0 AND name = "MAIN_MAIL_SMTPS_PW"; +UPDATE llx_const SET entity = 1 WHERE entity = 0 AND name = "MAIN_MAIL_EMAIL_TLS"; + + +create table llx_bank_account_extrafields +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp, + fk_object integer NOT NULL, + import_key varchar(14) -- import key +) ENGINE=innodb; + diff --git a/htdocs/install/mysql/tables/llx_actioncomm_resources.key.sql b/htdocs/install/mysql/tables/llx_actioncomm_resources.key.sql index caaa0969944..8c7bb4ad237 100644 --- a/htdocs/install/mysql/tables/llx_actioncomm_resources.key.sql +++ b/htdocs/install/mysql/tables/llx_actioncomm_resources.key.sql @@ -18,7 +18,7 @@ -- ============================================================================ -ALTER TABLE llx_actioncomm_resources ADD UNIQUE INDEX idx_actioncomm_resources_idx1 (fk_actioncomm, element_type, fk_element); +ALTER TABLE llx_actioncomm_resources ADD UNIQUE INDEX uk_actioncomm_resources(fk_actioncomm, element_type, fk_element); ALTER TABLE llx_actioncomm_resources ADD INDEX idx_actioncomm_resources_fk_element (fk_element); -- Pas de contrainte sur fk_source et fk_target car pointe sur differentes tables diff --git a/htdocs/install/mysql/tables/llx_bank_account_extrafields.key.sql b/htdocs/install/mysql/tables/llx_bank_account_extrafields.key.sql new file mode 100644 index 00000000000..0f6e8052115 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_bank_account_extrafields.key.sql @@ -0,0 +1,20 @@ +-- =================================================================== +-- Copyright (C) 2014 Florian Henry +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License 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 +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- =================================================================== + + +ALTER TABLE llx_bank_account_extrafields ADD INDEX idx_bank_account_extrafields (fk_object); diff --git a/htdocs/install/mysql/tables/llx_bank_account_extrafields.sql b/htdocs/install/mysql/tables/llx_bank_account_extrafields.sql new file mode 100644 index 00000000000..97b1508237c --- /dev/null +++ b/htdocs/install/mysql/tables/llx_bank_account_extrafields.sql @@ -0,0 +1,26 @@ +-- ======================================================================== +-- Copyright (C) 2014 Florian Henry +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License 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 +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- ======================================================================== + +create table llx_bank_account_extrafields +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp, + fk_object integer NOT NULL, + import_key varchar(14) -- import key +) ENGINE=innodb; + diff --git a/htdocs/install/mysql/tables/llx_contrat.sql b/htdocs/install/mysql/tables/llx_contrat.sql index 5efbcdfe1fa..0e75c50305b 100644 --- a/htdocs/install/mysql/tables/llx_contrat.sql +++ b/htdocs/install/mysql/tables/llx_contrat.sql @@ -23,6 +23,7 @@ create table llx_contrat rowid integer AUTO_INCREMENT PRIMARY KEY, ref varchar(30), -- contrat reference ref_supplier varchar(30), -- suplier contract ref + ref_ext varchar(30), -- external contract ref entity integer DEFAULT 1 NOT NULL, -- multi company id tms timestamp, datec datetime, -- creation date diff --git a/htdocs/install/mysql/tables/llx_facture.sql b/htdocs/install/mysql/tables/llx_facture.sql index 9757f749cd0..eada5b46c2e 100644 --- a/htdocs/install/mysql/tables/llx_facture.sql +++ b/htdocs/install/mysql/tables/llx_facture.sql @@ -3,6 +3,8 @@ -- Copyright (C) 2004-2012 Laurent Destailleur -- Copyright (C) 2005-2012 Regis Houssin -- Copyright (C) 2010 Juanjo Menent +-- Copyright (C) 2012 Cédric Salvador +-- Copyright (C) 2014 Raphaël Doursenaud -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -74,6 +76,10 @@ create table llx_facture note_public text, model_pdf varchar(255), import_key varchar(14), - extraparams varchar(255) -- for stock other parameters with json format + extraparams varchar(255), -- for stock other parameters with json format + + situation_cycle_ref smallint, -- situation cycle reference + situation_counter smallint, -- situation counter + situation_final smallint -- is the situation final ? )ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_facturedet.sql b/htdocs/install/mysql/tables/llx_facturedet.sql index 6a328d4688e..2c01234f4b9 100644 --- a/htdocs/install/mysql/tables/llx_facturedet.sql +++ b/htdocs/install/mysql/tables/llx_facturedet.sql @@ -3,6 +3,8 @@ -- Copyright (C) 2004-2005 Laurent Destailleur -- Copyright (C) 2005-2012 Regis Houssin -- Copyright (C) 2010 Juanjo Menent +-- Copyright (C) 2012 Cédric Salvador +-- Copyright (C) 2014 Raphaël Doursenaud -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -55,8 +57,11 @@ create table llx_facturedet fk_code_ventilation integer DEFAULT 0 NOT NULL, special_code integer UNSIGNED DEFAULT 0, -- code pour les lignes speciales rang integer DEFAULT 0, -- ordre d'affichage - import_key varchar(14) - + import_key varchar(14), + + situation_percent real, -- % progression of lines invoicing + fk_prev_id integer -- id of the line in the previous situation + )ENGINE=innodb; -- diff --git a/htdocs/install/mysql/tables/llx_printer_ipp.sql b/htdocs/install/mysql/tables/llx_printing.sql similarity index 77% rename from htdocs/install/mysql/tables/llx_printer_ipp.sql rename to htdocs/install/mysql/tables/llx_printing.sql index a19e05587d6..451564ff74b 100644 --- a/htdocs/install/mysql/tables/llx_printer_ipp.sql +++ b/htdocs/install/mysql/tables/llx_printing.sql @@ -1,5 +1,6 @@ -- ============================================================================ --- Copyright (C) 2013 Florian HENRY +-- Copyright (C) 2013 Florian HENRY +-- Copyright (C) 2014 Frederic France -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -16,15 +17,16 @@ -- -- ============================================================================ -CREATE TABLE llx_printer_ipp +CREATE TABLE llx_printing ( rowid integer AUTO_INCREMENT PRIMARY KEY, - tms timestamp, - datec datetime, + tms timestamp, + datec datetime, printer_name text NOT NULL, printer_location text NOT NULL, - printer_uri varchar(255) NOT NULL, + printer_id varchar(255) NOT NULL, copy integer NOT NULL DEFAULT '1', module varchar(16) NOT NULL, - login varchar(32) NOT NULL + driver varchar(16) NOT NULL, + userid integer )ENGINE=innodb; diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 57004f3cb16..86ab911c71b 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -362,6 +362,8 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action'))) $beforeversionarray=explode('.','3.7.9'); // target is before this if (versioncompare($versiontoarray,$afterversionarray) >= 0 && versioncompare($versiontoarray,$beforeversionarray) <= 0) { + migrate_event_assignement($db,$langs,$conf); + // Reload modules (this must be always and only into last targeted version) $listofmodule=array( 'MAIN_MODULE_AGENDA', @@ -391,6 +393,7 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action'))) $db->commit(); $db->close(); + // Actions for all version (not in database) migrate_delete_old_files($db,$langs,$conf); @@ -3519,6 +3522,83 @@ function migrate_categorie_association($db,$langs,$conf) print ''; } +/** + * Migrate event assignement to owner + * + * @param DoliDB $db Database handler + * @param Translate $langs Object langs + * @param Conf $conf Object conf + * @return void + */ +function migrate_event_assignement($db,$langs,$conf) +{ + print ''; +} + /** * Migration directory * diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 0b328e705a7..bca163db8bd 100755 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -382,10 +382,12 @@ ExtrafieldSelectList = Select from table ExtrafieldSeparator=Separator ExtrafieldCheckBox=Checkbox ExtrafieldRadio=Radio button +ExtrafieldCheckBoxFromList= Checkbox from table ExtrafieldParamHelpselect=Parameters list have to be like key,value

for example :
1,value1
2,value2
3,value3
...

In order to have the list depending on another :
1,value1|parent_list_code:parent_key
2,value2|parent_list_code:parent_key ExtrafieldParamHelpcheckbox=Parameters list have to be like key,value

for example :
1,value1
2,value2
3,value3
... ExtrafieldParamHelpradio=Parameters list have to be like key,value

for example :
1,value1
2,value2
3,value3
... -ExtrafieldParamHelpsellist=Parameters list comes from a table
Syntax : table_name:label_field:id_field::filter
Example : c_typent:libelle:id::filter

filter can be a simple test (eg active=1) to display only active value
if you want to filter on extrafields use syntaxt extra.fieldcode=... (where field code is the code of extrafield)

In order to have the list depending on another :
c_typent:libelle:id:parent_list_code|parent_column:filter +ExtrafieldParamHelpsellist=Parameters list comes from a table
Syntax : table_name:label_field:id_field::filter
Example : c_typent:libelle:id::filter

filter can be a simple test (eg active=1) to display only active value
if you want to filter on extrafields use syntaxt extra.fieldcode=... (where field code is the code of extrafield)

In order to have the list depending on another :
c_typent:libelle:id:parent_list_code|parent_column:filter +ExtrafieldParamHelpchkbxlst=Parameters list comes from a table
Syntax : table_name:label_field:id_field::filter
Example : c_typent:libelle:id::filter

filter can be a simple test (eg active=1) to display only active value
if you want to filter on extrafields use syntaxt extra.fieldcode=... (where field code is the code of extrafield)

In order to have the list depending on another :
c_typent:libelle:id:parent_list_code|parent_column:filter LibraryToBuildPDF=Library used to build PDF WarningUsingFPDF=Warning: Your conf.php contains directive dolibarr_pdf_force_fpdf=1. This means you use the FPDF library to generate PDF files. This library is old and does not support a lot of features (Unicode, image transparency, cyrillic, arab and asiatic languages, ...), so you may experience errors during PDF generation.
To solve this and have a full support of PDF generation, please download TCPDF library, then comment or remove the line $dolibarr_pdf_force_fpdf=1, and add instead $dolibarr_lib_TCPDF_PATH='path_to_TCPDF_dir' LocalTaxDesc=Some countries apply 2 or 3 taxes on each invoice line. If this is the case, choose type for second and third tax and its rate. Possible type are:
1 : local tax apply on products and services without vat (vat is not applied on local tax)
2 : local tax apply on products and services before vat (vat is calculated on amount + localtax)
3 : local tax apply on products without vat (vat is not applied on local tax)
4 : local tax apply on products before vat (vat is calculated on amount + localtax)
5 : local tax apply on services without vat (vat is not applied on local tax)
6 : local tax apply on services before vat (vat is calculated on amount + localtax) @@ -1038,7 +1040,7 @@ SendingMailSetup=Setup of sendings by email SendmailOptionNotComplete=Warning, on some Linux systems, to send email from your email, sendmail execution setup must contains option -ba (parameter mail.force_extra_parameters into your php.ini file). If some recipients never receive emails, try to edit this PHP parameter with mail.force_extra_parameters = -ba). PathToDocuments=Path to documents PathDirectory=Directory -SendmailOptionMayHurtBuggedMTA=Feature to send mails using method "PHP mail direct" will generate a mail message that might be not correctly parsed by some receiving mail servers. Result is that some mails can't be read by people hosted by thoose bugged platforms. It's case for some Internet providers (Ex: Orange in France). This is not a problem into Dolibarr nor into PHP but onto receiving mail server. You can however add option MAIN_FIX_FOR_BUGGED_MTA to 1 into setup - other to modify Dolibarr to avoid this. However, you may experience problem with other servers that respect strictly the SMTP standard. The other solution (recommanded) is to use the method "SMTP socket library" that has no disadvantages. +SendmailOptionMayHurtBuggedMTA=Feature to send mails using method "PHP mail direct" will generate a mail message that might be not correctly parsed by some receiving mail servers. Result is that some mails can't be read by people hosted by those bugged platforms. It's case for some Internet providers (Ex: Orange in France). This is not a problem into Dolibarr nor into PHP but onto receiving mail server. You can however add option MAIN_FIX_FOR_BUGGED_MTA to 1 into setup - other to modify Dolibarr to avoid this. However, you may experience problem with other servers that respect strictly the SMTP standard. The other solution (recommended) is to use the method "SMTP socket library" that has no disadvantages. TranslationSetup=Configuration de la traduction TranslationDesc=Choice of language visible on screen can be modified:
* Globally from menu Home - Setup - Display
* For user only from tab User display of user card (click on login on top of screen). TotalNumberOfActivatedModules=Total number of activated feature modules: %s @@ -1393,6 +1395,7 @@ RSSUrlExample=An interesting RSS feed MailingSetup=EMailing module setup MailingEMailFrom=Sender EMail (From) for emails sent by emailing module MailingEMailError=Return EMail (Errors-to) for emails with errors +MailingDelay=Seconds to wait after sending next message ##### Notification ##### NotificationSetup=EMail notification module setup NotificationEMailFrom=Sender EMail (From) for emails sent for notifications @@ -1415,7 +1418,7 @@ AdvancedEditor=Advanced editor ActivateFCKeditor=Activate advanced editor for: FCKeditorForCompany=WYSIWIG creation/edition of elements description and note (except products/services) FCKeditorForProduct=WYSIWIG creation/edition of products/services description and note -FCKeditorForProductDetails=WYSIWIG creation/edition of products details lines for all entities (proposals, orders, invoices, etc...). Warning: Using this option for this case is seriously not recommanded as it can create problems with special characters and page formating when building PDF files. +FCKeditorForProductDetails=WYSIWIG creation/edition of products details lines for all entities (proposals, orders, invoices, etc...). Warning: Using this option for this case is seriously not recommended as it can create problems with special characters and page formating when building PDF files. FCKeditorForMailing= WYSIWIG creation/edition for mass eMailings (Tools->eMailing) FCKeditorForUserSignature=WYSIWIG creation/edition of user signature FCKeditorForMail=WYSIWIG creation/edition for all mail (except Outils->eMailing) diff --git a/htdocs/langs/en_US/agenda.lang b/htdocs/langs/en_US/agenda.lang index 1cc01ec2e7b..9ed2d79edd2 100644 --- a/htdocs/langs/en_US/agenda.lang +++ b/htdocs/langs/en_US/agenda.lang @@ -68,7 +68,7 @@ DateActionDoneEnd= Real end date DateActionStart= Start date DateActionEnd= End date AgendaUrlOptions1=You can also add following parameters to filter output: -AgendaUrlOptions2=login=%s to restrict output to actions created by, assigned to or done by user %s. +AgendaUrlOptions2=login=%s to restrict output to actions created by or assigned to user %s. AgendaUrlOptions3=logina=%s to restrict output to actions owned by a user %s. AgendaUrlOptions4=logint=%s to restrict output to actions assigned to user %s. AgendaUrlOptionsProject=project=PROJECT_ID to restrict output to actions associated to project PROJECT_ID. diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index 12778d6b9ea..ccf994aff95 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -389,7 +389,7 @@ DisabledBecausePayments=Not possible since there are some payments CantRemovePaymentWithOneInvoicePaid=Can't remove payment since there is at least one invoice classified paid ExpectedToPay=Expected payment PayedByThisPayment=Paid by this payment -ClosePaidInvoicesAutomatically=Classify "Paid" all standard or replacement invoices entirely paid. +ClosePaidInvoicesAutomatically=Classify "Paid" all standard, situation or replacement invoices entirely paid. ClosePaidCreditNotesAutomatically=Classify "Paid" all credit notes entirely paid back. AllCompletelyPayedInvoiceWillBeClosed=All invoice with no remain to pay will be automatically closed to status "Paid". ToMakePayment=Pay @@ -411,3 +411,20 @@ TypeContact_invoice_supplier_internal_SALESREPFOLL=Representative following-up s TypeContact_invoice_supplier_external_BILLING=Supplier invoice contact TypeContact_invoice_supplier_external_SHIPPING=Supplier shipping contact TypeContact_invoice_supplier_external_SERVICE=Supplier service contact +# Situation invoices +InvoiceFirstSituationAsk=First situation invoice +InvoiceFirstSituationDesc=The situation invoices are tied to situations related to a progression, for example the progression of a construction. Each situation is tied to an invoice. +InvoiceSituation=Situation invoice +InvoiceSituationAsk=Invoice following the situation +InvoiceSituationDesc=Create a new situation following an already existing one +SituationAmount=Situation invoice amount(net) +SituationDeduction=Situation subtraction +Progress=Progress +ModifyAllLines=Modify all lines +CreateNextSituationInvoice=Create next situation +NotLastInCycle=This invoice in not the last in cycle and must not be modified. +DisabledBecauseNotLastInCycle=The next situation already exists. +DisabledBecauseFinal=This situation is final. +CantBeLessThanMinPercent=The progress can't be smaller than its value in the previous situation. +NoSituations=No opened situations +InvoiceSituationLast=Final and general invoice diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 35b7da13728..08b031690b4 100755 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -91,6 +91,8 @@ ErrorModuleSetupNotComplete=Setup of module looks to be uncomplete. Go on Setup ErrorBadMask=Error on mask ErrorBadMaskFailedToLocatePosOfSequence=Error, mask without sequence number ErrorBadMaskBadRazMonth=Error, bad reset value +ErrorMaxNumberReachForThisMask=Max number reach for this mask +ErrorCounterMustHaveMoreThan3Digits=Counter must have more than 3 digits ErrorSelectAtLeastOne=Error. Select at least one entry. ErrorProductWithRefNotExist=Product with reference '%s' don't exist ErrorDeleteNotPossibleLineIsConsolidated=Delete not possible because record is linked to a bank transation that is conciliated diff --git a/htdocs/langs/en_US/install.lang b/htdocs/langs/en_US/install.lang index 20abe7b9c70..c296bd788e8 100644 --- a/htdocs/langs/en_US/install.lang +++ b/htdocs/langs/en_US/install.lang @@ -206,6 +206,7 @@ MigrationProjectTaskTime=Update time spent in seconds MigrationActioncommElement=Update data on actions MigrationPaymentMode=Data migration for payment mode MigrationCategorieAssociation=Migration of categories +MigrationEvents=Migration of events to add event owner into assignement table ShowNotAvailableOptions=Show not available options HideNotAvailableOptions=Hide not available options \ No newline at end of file diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index bfded6f40e2..0f41a43c90f 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -260,6 +260,7 @@ days=days Hours=Hours Minutes=Minutes Seconds=Seconds +Weeks=Weeks Today=Today Yesterday=Yesterday Tomorrow=Tomorrow @@ -685,6 +686,7 @@ XMoreLines=%s line(s) hidden PublicUrl=Public URL AddBox=Add box SelectElementAndClickRefresh=Select an element and click Refresh +PrintFile=Print File %s # Week day Monday=Monday Tuesday=Tuesday diff --git a/htdocs/langs/en_US/printgcp.lang b/htdocs/langs/en_US/printgcp.lang new file mode 100644 index 00000000000..ded5fb63d6e --- /dev/null +++ b/htdocs/langs/en_US/printgcp.lang @@ -0,0 +1,25 @@ +# Dolibarr language file - Source file is en_US - printgccp +PRINTGCP=Google Cloud Print +PrintGCPDesc=This driver allow to send documents directly to a printer with Google Cloud Print. +PrintingDriverDescprintgcp=Configuration variables for printing driver Google Cloud Print. +PrintTestDescprintgcp=List of Printers for Google Cloud Print. +PRINTGCP_LOGIN=Google Account Login +PRINTGCP_PASSWORD=Google Account Password +STATE_ONLINE=Online +STATE_UNKNOWN=Unknown +STATE_OFFLINE=Offline +STATE_DORMANT=Offline for quite a while +TYPE_GOOGLE=Google +TYPE_HP=HP Printer +TYPE_DOCS=DOCS +TYPE_DRIVE=Google Drive +TYPE_FEDEX=Fedex +TYPE_ANDROID_CHROME_SNAPSHOT=Android +TYPE_IOS_CHROME_SNAPSHOT=IOS +GCP_Name=Name +GCP_displayName=Display Name +GCP_Id=Printer Id +GCP_OwnerName=Owner Name +GCP_State=Printer State +GCP_connectionStatus=Online State +GCP_Type=Printer Type diff --git a/htdocs/langs/en_US/printing.lang b/htdocs/langs/en_US/printing.lang new file mode 100644 index 00000000000..77c63884636 --- /dev/null +++ b/htdocs/langs/en_US/printing.lang @@ -0,0 +1,10 @@ +# Dolibarr language file - Source file is en_US - printing +PrintingSetup=Setup of Printing System +PrintingDesc=This module adds a Print button to send documents directly to a printer with various module. +ModuleDriverSetup=Setup Module Driver +PrintingDriverDesc=Configuration variables for printing driver. +ListDrivers=List of drivers +PrintTestDesc=List of Printers. +FileWasSentToPrinter=File %s was sent to printer +NoActivePrintingModuleFound=No active module to print document +PleaseSelectaDriverfromList=Please select a driver from list. diff --git a/htdocs/langs/en_US/printipp.lang b/htdocs/langs/en_US/printipp.lang index 835e6827f12..e85d53627c4 100644 --- a/htdocs/langs/en_US/printipp.lang +++ b/htdocs/langs/en_US/printipp.lang @@ -1,6 +1,9 @@ # Dolibarr language file - Source file is en_US - printipp +PRINTIPP=PrintIPP Driver PrintIPPSetup=Setup of Direct Print module -PrintIPPDesc=This module adds a Print button to send documents directly to a printer. It requires a Linux system with CUPS installed. +PrintIPPDesc=This driver allow to send documents directly to a printer. It requires a Linux system with CUPS installed. +PrintingDriverDescprintipp=Configuration variables for printing driver PrintIPP. +PrintTestDescprintipp=List of Printers for driver PrintIPP. PRINTIPP_ENABLED=Show "Direct print" icon in document lists PRINTIPP_HOST=Print server PRINTIPP_PORT=Port @@ -12,3 +15,23 @@ NoDefaultPrinterDefined=No default printer defined DefaultPrinter=Default printer Printer=Printer CupsServer=CUPS Server +IPP_Uri=Printer Uri +IPP_Name=Printer Name +IPP_State=Printer State +IPP_State_reason=State reason +IPP_State_reason1=State reason1 +IPP_BW=BW +IPP_Color=Color +IPP_Device=Device +IPP_Media=Printer media +IPP_Supported=Type of media +STATE_IPP_idle=Idle +STATE_IPP_stopped=Stopped +STATE_IPP_paused=Paused +STATE_IPP_toner-low-report=Low Toner +STATE_IPP_none=None +MEDIA_IPP_stationery=Stationery +MEDIA_IPP_thermal=Thermal +IPP_COLOR_print-black=BW Printer +IPP_COLOR_print-color=Color Printer +IPP_COLOR_=No diff --git a/htdocs/langs/en_US/projects.lang b/htdocs/langs/en_US/projects.lang index 84624b219f9..b3c150d1687 100644 --- a/htdocs/langs/en_US/projects.lang +++ b/htdocs/langs/en_US/projects.lang @@ -103,6 +103,7 @@ CloneContacts=Clone contacts CloneNotes=Clone notes CloneProjectFiles=Clone project joined files CloneTaskFiles=Clone task(s) joined files (if task(s) cloned) +CloneMoveDate=Update project/tasks dates from now ? ConfirmCloneProject=Are you sure to clone this project ? ProjectReportDate=Change task date according project start date ErrorShiftTaskDate=Impossible to shift task date according to new project start date diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 4397bb313fa..4e783fafce1 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -382,10 +382,12 @@ ExtrafieldSelectList = Liste issue d'une table ExtrafieldSeparator=Séparateur de champ ExtrafieldCheckBox=Case à cocher ExtrafieldRadio=Bouton radio +ExtrafieldCheckBoxFromList= Case à cocher issue d'une table ExtrafieldParamHelpselect=La liste doit être de la forme clef,valeur

par exemple :
1,valeur1
2,valeur2
3,valeur3
...

Pour que la liste soit dépendante d'une autre :
1,valeur1|code_liste_parent:clef_parent
2,valeur2|code_liste_parent:clef_parent ExtrafieldParamHelpcheckbox=La liste doit être de la forme clef,valeur

par exemple :
1,valeur1
2,valeur2
3,valeur3
... ExtrafieldParamHelpradio=La liste doit être de la forme clef,valeur

par exemple :
1,valeur1
2,valeur2
3,valeur3
... ExtrafieldParamHelpsellist=La liste vient d'une table
Syntaxe:
nom_de_table:nom_de_champ:id_champ::filtre
Exemple :
c_typent:libelle:id::filter

filter peux être un test simple (exemple active=1 pour ne proposer que les valeur active)
si vous voulez faire un filtre sur des attributs supplémentaires, utilisez la syntax extra.champ=... (où champ est la code de l'attribut supplémentaire)

Pour que la liste soit dépendante d'une autre :
c_typent:libelle:id:code_liste_parent|colonne_parent:filter +ExtrafieldParamHelpchkbxlst=Les cases à cocher viennent d'une table
Syntaxe:
nom_de_table:nom_de_champ:id_champ::filtre
Exemple :
c_typent:libelle:id::filter

filter peux être un test simple (exemple active=1 pour ne proposer que les valeur active)
si vous voulez faire un filtre sur des attributs supplémentaires, utilisez la syntax extra.champ=... (où champ est la code de l'attribut supplémentaire)

Pour que la liste soit dépendante d'une autre :
c_typent:libelle:id:code_liste_parent|colonne_parent:filter LibraryToBuildPDF=Bibliothèque utilisée pour la génération des PDF WarningUsingFPDF=Attention : votre fichier conf.php contient la directive dolibarr_pdf_force_fpdf=1. Cela signifie que vous utilisez la librairie FPDF pour générer vos fichiers PDF. Cette librairie est ancienne et ne couvre pas de nombreuses fonctionnalités (Unicode, transparence des images, langues cyrilliques, arabes ou asiatiques...), aussi vous pouvez rencontrer des problèmes durant la génération des PDF.
Pour résoudre cela et avoir une prise en charge complète de PDF, vous pouvez télécharger la bibliothèque TCPDF puis commenter ou supprimer la ligne $dolibarr_pdf_force_fpdf=1, et ajouter à la place $dolibarr_lib_TCPDF_PATH='chemin_vers_TCPDF' LocalTaxDesc=Certains pays appliquent 2 voire 3 taux sur chaque ligne de facture. Si c'est le cas, choisissez le type du deuxième et troisième taux et sa valeur. Les types possibles sont:
1 : taxe locale sur les produits et services hors tva (la tva n'est pas appliquée sur la taxe locale)
2 : taxe locale sur les produits et services avant tva (la tva est appliquée sur le montant + la taxe locale)
3 : taxe locale uniquement sur les produits hors tva (la tva n'est pas appliquée sur la taxe locale)
4 : taxe locale uniquement sur les produits avant tva (la tva est appliquée sur le montant + la taxe locale)
5 : taxe locale uniquement sur les services hors tva (la tva n'est pas appliquée sur la taxe locale)
6 : taxe locale uniquement sur les service avant tva (la tva est appliquée sur le montant + la taxe locale) diff --git a/htdocs/langs/fr_FR/bills.lang b/htdocs/langs/fr_FR/bills.lang index 24ebe5ff923..22c80d41300 100644 --- a/htdocs/langs/fr_FR/bills.lang +++ b/htdocs/langs/fr_FR/bills.lang @@ -410,3 +410,21 @@ TypeContact_invoice_supplier_internal_SALESREPFOLL=Responsable suivi facture fou TypeContact_invoice_supplier_external_BILLING=Contact fournisseur facturation TypeContact_invoice_supplier_external_SHIPPING=Contact fournisseur livraison TypeContact_invoice_supplier_external_SERVICE=Contact fournisseur prestation +# Factures de situation +InvoiceFirstSituationAsk=Facture de première situation +InvoiceFirstSituationDesc=Les factures de situation correspondent aux situations liées à un avancement, par exemple l'avancement des travaux dans le cadre d’un chantier (BTP). Chaque situation correspond à une facture. +InvoiceFirstSituation=Facture de première situation +InvoiceSituationAsk=Facture suivant la situation +InvoiceSituationDesc=Création d'une nouvelle situation qui fera suite à une situation déjà ouverte. +InvoiceSituation=Facture de situation +SituationAmount=Montant HT situation +SituationDeduction=Déduction situation +Progress=Avanct. +ModifyAllLines=Modifier toutes les lignes +CreateNextSituationInvoice=Créer situation suivante +NotLastInCycle=Cette facture n'est pas la dernière du cycle, il ne faut pas la modifier. +DisabledBecauseNotLastInCycle=La situation suivante existe déjà. +DisabledBecauseFinal=Cette situation est finale. +CantBeLessThanMinPercent=L'avancement d'une ligne ne peut pas être inférieur à sa valeur à la situation précédente. +NoSituations=Pas de situations en cours +InvoiceSituationLast=Décompte général et définitif diff --git a/htdocs/langs/fr_FR/errors.lang b/htdocs/langs/fr_FR/errors.lang index e880dbdac8d..4f82ea72bca 100644 --- a/htdocs/langs/fr_FR/errors.lang +++ b/htdocs/langs/fr_FR/errors.lang @@ -91,6 +91,8 @@ ErrorModuleSetupNotComplete=La configuration du module semble incomplète. Aller ErrorBadMask=Erreur sur le masque ErrorBadMaskFailedToLocatePosOfSequence=Erreur, masque sans numéro de séquence ErrorBadMaskBadRazMonth=Erreur, mauvais valeur de remise à zéro +ErrorMaxNumberReachForThisMask=Valeur maximale atteinte pour ce masque +ErrorCounterMustHaveMoreThan3Digits=Le compteur doit avoir plus de 3 chiffres ErrorSelectAtLeastOne=Erreur. Sélectionnez au moins une entrée. ErrorProductWithRefNotExist=La référence produit '%s' n'existe pas ErrorDeleteNotPossibleLineIsConsolidated=Suppression impossible car l'enregistrement porte sur au moins une transaction bancaire rapprochée diff --git a/htdocs/langs/fr_FR/projects.lang b/htdocs/langs/fr_FR/projects.lang index 29a11afec29..0bdc1526675 100644 --- a/htdocs/langs/fr_FR/projects.lang +++ b/htdocs/langs/fr_FR/projects.lang @@ -103,6 +103,7 @@ CloneContacts=Cloner les contacts CloneNotes=Cloner les notes CloneProjectFiles=Cloner les pièces jointes du projet CloneTaskFiles=Cloner les pièces jointes des tâche(s) (si tâche(s) cloner) +CloneMoveDate=Deplacer les date projets/taches sur maintenant ConfirmCloneProject=Êtes-vous sûr de vouloir cloner ce projet ? ProjectReportDate=Reporter les dates des tâches en fonction de la date de départ. ErrorShiftTaskDate=Une erreur s'est produite dans le report des dates des tâches. diff --git a/htdocs/livraison/class/livraison.class.php b/htdocs/livraison/class/livraison.class.php index dfad1c7e7b8..ccde9484b0d 100644 --- a/htdocs/livraison/class/livraison.class.php +++ b/htdocs/livraison/class/livraison.class.php @@ -660,13 +660,13 @@ class Livraison extends CommonObject $result=''; $urlOption=''; + $label=$langs->trans("ShowReceiving").': '.$this->ref; - $lien = ''; + $lien = ''; $lienfin=''; $picto='sending'; - $label=$langs->trans("ShowReceiving").': '.$this->ref; if ($withpicto) $result.=($lien.img_object($label, $picto, 'class="classfortooltip"').$lienfin); if ($withpicto && $withpicto != 2) $result.=' '; diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index b805e098706..b6244802318 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -736,7 +736,7 @@ if ((! empty($conf->browser->layout) && $conf->browser->layout == 'phone') // If we force to use jmobile, then we reenable javascript if (! empty($conf->dol_use_jmobile)) $conf->use_javascript_ajax=1; // Replace themes bugged with jmobile with eldy -if (! empty($conf->dol_use_jmobile) && in_array($conf->theme,array('bureau2crea','cameleo'))) +if (! empty($conf->dol_use_jmobile) && in_array($conf->theme,array('bureau2crea','cameleo','amarok'))) { $conf->theme='eldy'; $conf->css = "/theme/".$conf->theme."/style.css.php"; @@ -976,7 +976,7 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs // Displays meta print ''."\n"; // Evite indexation par robots print ''."\n"; - if ($conf->global->MAIN_FEATURES_LEVEL == 2 || ! empty($conf->global->MAIN_ACTIVATE_HTML5)) print ''."\n"; // Needed for Responsive Web Design + if (! empty($conf->global->MAIN_ACTIVATE_HTML5)) print ''."\n"; // Needed for Responsive Web Design $favicon=dol_buildpath('/theme/'.$conf->theme.'/img/favicon.ico',1); if (! empty($conf->global->MAIN_FAVICON_URL)) $favicon=$conf->global->MAIN_FAVICON_URL; print ''."\n"; @@ -988,6 +988,7 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs $appli='Dolibarr'; if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $appli=$conf->global->MAIN_APPLICATION_TITLE; + if ($title && ! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/noapp/',$conf->global->MAIN_HTML_TITLE)) print ''.dol_htmlentities($title).''; if ($title) print ''.dol_htmlentities($appli.' - '.$title).''; else print "".dol_htmlentities($appli).""; print "\n"; diff --git a/htdocs/margin/index.php b/htdocs/margin/index.php index d3897faa551..04a2ba0d544 100644 --- a/htdocs/margin/index.php +++ b/htdocs/margin/index.php @@ -1,5 +1,6 @@ + * Copyright (C) 2014 Marcos García * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,5 +22,15 @@ * \brief Page d'index du module margin */ -require 'productMargins.php'; +require '../main.inc.php'; + +if ($user->rights->produit->lire) { + $page = 'productMargins'; +} elseif ($user->rights->societe->lire) { + $page = 'customerMargins'; +} else { + $page = 'agentMargins'; +} + +header('Location: '.dol_buildpath('/margin/'.$page.'.php', 1)); diff --git a/htdocs/margin/lib/margins.lib.php b/htdocs/margin/lib/margins.lib.php index d3ffd9c1bf4..1f904c44f2d 100644 --- a/htdocs/margin/lib/margins.lib.php +++ b/htdocs/margin/lib/margins.lib.php @@ -1,5 +1,6 @@ + * Copyright (C) 2014 Marcos García * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -56,21 +57,25 @@ function marges_admin_prepare_head() */ function marges_prepare_head() { - global $langs, $conf; + global $langs, $conf, $user; $langs->load("marges@marges"); $h = 0; $head = array(); - $head[$h][0] = DOL_URL_ROOT."/margin/productMargins.php"; - $head[$h][1] = $langs->trans("ProductMargins"); - $head[$h][2] = 'productMargins'; - $h++; + if ($user->rights->produit->lire) { + $head[$h][0] = DOL_URL_ROOT."/margin/productMargins.php"; + $head[$h][1] = $langs->trans("ProductMargins"); + $head[$h][2] = 'productMargins'; + $h++; + } - $head[$h][0] = DOL_URL_ROOT."/margin/customerMargins.php"; - $head[$h][1] = $langs->trans("CustomerMargins"); - $head[$h][2] = 'customerMargins'; - $h++; + if ($user->rights->societe->lire) { + $head[$h][0] = DOL_URL_ROOT."/margin/customerMargins.php"; + $head[$h][1] = $langs->trans("CustomerMargins"); + $head[$h][2] = 'customerMargins'; + $h++; + } $head[$h][0] = DOL_URL_ROOT."/margin/agentMargins.php"; $head[$h][1] = $langs->trans("SalesRepresentativeMargins"); diff --git a/htdocs/printipp/lib/index.html b/htdocs/printing/admin/index.html similarity index 100% rename from htdocs/printipp/lib/index.html rename to htdocs/printing/admin/index.html diff --git a/htdocs/printing/admin/printing.php b/htdocs/printing/admin/printing.php new file mode 100644 index 00000000000..63784e560f0 --- /dev/null +++ b/htdocs/printing/admin/printing.php @@ -0,0 +1,277 @@ + + * Copyright (C) 2014 Frederic France + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License 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 + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/printing/admin/printing.php + * \ingroup printing + * \brief Page to setup printing module + */ + +require '../../main.inc.php'; + +require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/modules_printing.php'; +require_once DOL_DOCUMENT_ROOT.'/printing/lib/printing.lib.php'; + +$langs->load("admin"); +$langs->load("printing"); + +if (! $user->admin) accessforbidden(); + +$action = GETPOST('action','alpha'); +$mode = GETPOST('mode','alpha'); +$value = GETPOST('value','alpha'); +$varname = GETPOST('varname', 'alpha'); +$driver = GETPOST('driver', 'alpha'); + +if (! empty($driver)) $langs->load($driver); + +if (!$mode) $mode='config'; + +/* + * Action + */ + +if (($mode == 'test' || $mode == 'setup') && empty($driver)) +{ + setEventMessage($langs->trans('PleaseSelectaDriverfromList')); + header("Location: ".$_SERVER['PHP_SELF'].'?mode=config'); + exit; +} + +if ($action == 'setconst' && $user->admin) +{ + $error=0; + $db->begin(); + foreach ($_POST['setupdriver'] as $setupconst) { + //print '
'.print_r($setupconst, true).'
'; + $result=dolibarr_set_const($db, $setupconst['varname'],$setupconst['value'],'chaine',0,'',$conf->entity); + if (! $result > 0) $error++; + } + + if (! $error) + { + $db->commit(); + setEventMessage($langs->trans("SetupSaved")); + } + else + { + $db->rollback(); + dol_print_error($db); + } + $action=''; +} + +if ($action == 'setvalue' && $user->admin) +{ + $db->begin(); + + $result=dolibarr_set_const($db, $varname, $value,'chaine',0,'',$conf->entity); + if (! $result > 0) $error++; + + if (! $error) + { + $db->commit(); + setEventMessage($langs->trans("SetupSaved")); + } + else + { + $db->rollback(); + dol_print_error($db); + } + $action = ''; +} + +/* + * View + */ + +$form = new Form($db); + +llxHeader('',$langs->trans("PrintingSetup")); + +$linkback=''.$langs->trans("BackToModuleList").''; +print_fiche_titre($langs->trans("PrintingSetup"),$linkback,'setup'); + +$head=printingadmin_prepare_head(); + +if ($mode == 'setup' && $user->admin) +{ + print '
'; + print ''; + print ''; + + dol_fiche_head($head, $mode, $langs->trans("ModuleDriverSetup"), 0, 'technic'); + + print $langs->trans("PrintingDriverDesc".$driver)."

\n"; + + print '
'.$langs->trans("DraftBills").' ('.$num.')
'.$langs->trans("DraftBills").' '.$num.'
'; + + print '
'; + print ''.$langs->trans('MigrationEvents')."
\n"; + + $error = 0; + + dolibarr_install_syslog("upgrade2::migrate_event_assignement"); + + $db->begin(); + + $sqlSelect = "SELECT a.id, a.fk_user_action"; + $sqlSelect.= " FROM ".MAIN_DB_PREFIX."actioncomm as a"; + $sqlSelect.= " LEFT JOIN ".MAIN_DB_PREFIX."actioncomm_resources as ar ON ar.fk_actioncomm = a.id AND ar.element_type = 'user' AND ar.fk_element = a.fk_user_action"; + $sqlSelect.= " WHERE fk_user_action > 0 AND fk_user_action NOT IN (SELECT fk_element FROM ".MAIN_DB_PREFIX."actioncomm_resources as ar WHERE ar.fk_actioncomm = a.id AND ar.element_type = 'user')"; + $sqlSelect.= " ORDER BY a.id"; + //print $sqlSelect; + + $resql = $db->query($sqlSelect); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); + + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); + + $sqlUpdate = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element) "; + $sqlUpdate.= "VALUES(".$obj->id.", 'user', ".$obj->fk_user_action.")"; + + $result=$db->query($sqlUpdate); + if (! $result) + { + $error++; + dol_print_error($db); + } + print ". "; + $i++; + } + } + else + { + print $langs->trans('AlreadyDone')."
\n"; + } + + if (! $error) + { + $db->commit(); + } + else + { + $db->rollback(); + } + } + else + { + dol_print_error($db); + $db->rollback(); + } + + + print '
'."\n"; + $var=true; + print ''; + print ''; + print ''; + print "\n"; + + if (! empty($driver)) { + require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php'; + $classname = 'printing_'.$driver; + $langs->load($driver); + $printer = new $classname($db); + //print '
'.print_r($printer, true).'
'; + $i=0; + foreach ($printer->conf as $key) { + $var=!$var; + print ''; + print ''.$langs->trans($key['varname']).''; + $i++; + } + } else { + print $langs->trans('PleaseSelectaDriverfromList'); + } + + print '
'.$langs->trans("Parameters").''.$langs->trans("Value").'
'; + print ''; + print ''; + print ' '.($key['example']!=''?$langs->trans("Example").' : '.$key['example']:''); + print '
'; + if (! empty($driver)) { + print '
'; + } + print ''; + dol_fiche_end(); + +} +if ($mode == 'config' && $user->admin) +{ + dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"), 0, 'technic'); + + print $langs->trans("PrintingDesc")."

\n"; + + print ''."\n"; + + $var=true; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + $object = new PrintingDriver($db); + $result = $object->listDrivers($db, 10); + foreach ($result as $driver) { + require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php'; + $classname = 'printing_'.$driver; + $langs->load($driver); + $printer = new $classname($db); + //print '
'.print_r($printer, true).'
'; + $var=!$var; + print ''; + print ''; + print ''; + print ''; + print ''."\n"; + } + + print '
'.$langs->trans("Description").''.$langs->trans("Active").''.$langs->trans("Setup").''.$langs->trans("Test").'
'.img_picto('', $printer->picto).$langs->trans($printer->desc).''; + if (! empty($conf->use_javascript_ajax)) + { + print ajax_constantonoff($printer->active); + } + else + { + if (empty($conf->global->{$printer->conf})) + { + print ''.img_picto($langs->trans("Disabled"),'off').''; + } + else + { + print ''.img_picto($langs->trans("Enabled"),'on').''; + } + } + print ''.img_picto('', 'setup').''.img_picto('', 'setup').'
'; + + dol_fiche_end(); +} + +if ($mode == 'test' && $user->admin) +{ + dol_fiche_head($head, $mode, $langs->trans("PrintingTest"), 0, 'technic'); + + print $langs->trans('PrintTestDesc'.$driver)."

\n"; + + print ''; + if (! empty($driver)) { + require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php'; + $classname = 'printing_'.$driver; + $langs->load($driver); + $printer = new $classname($db); + //print '
'.print_r($printer, true).'
'; + print $printer->listAvailablePrinters(); + + } else { + print $langs->trans('PleaseSelectaDriverfromList'); + } + print '
'; + + dol_fiche_end(); +} + +if ($mode == 'userconf' && $user->admin) +{ + dol_fiche_head($head, $mode, $langs->trans("UserConf"), 0, 'technic'); + + print $langs->trans('PrintUserConfDesc'.$driver)."

\n"; + + print ''; + $var=true; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + $sql = 'SELECT p.rowid, p.printer_name, p.printer_location, p.printer_id, p.copy, p.module, p.driver, p.userid, u.login FROM '.MAIN_DB_PREFIX.'printing as p, '.MAIN_DB_PREFIX.'user as u WHERE p.userid=u.rowid'; + $resql = $db->query($sql); + while ($row=$db->fetch_array($resql)) { + $var=!$var; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + } + print '
'.$langs->trans("User").''.$langs->trans("PrintModule").''.$langs->trans("PrintDriver").''.$langs->trans("Printer").''.$langs->trans("PrinterLocation").''.$langs->trans("PrinterId").''.$langs->trans("NumberOfCopy").''.$langs->trans("Delete").'
'.$row['login'].''.$row['module'].''.$row['driver'].''.$row['printer_name'].''.$row['printer_location'].''.$row['printer_id'].''.$row['copy'].''.img_picto($langs->trans("Delete"), 'delete').'
'; + + dol_fiche_end(); + +} + +llxFooter(); + +$db->close(); diff --git a/htdocs/printipp/index.php b/htdocs/printing/index.php similarity index 61% rename from htdocs/printipp/index.php rename to htdocs/printing/index.php index a130805f16e..e8669f44585 100644 --- a/htdocs/printipp/index.php +++ b/htdocs/printing/index.php @@ -1,5 +1,6 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,20 +17,21 @@ */ /** - * \file htdocs/printipp/index.php - * \ingroup printipp - * \brief Printipp + * \file htdocs/printing/index.php + * \ingroup printing + * \brief Printing */ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/dolprintipp.class.php'; -llxHeader("",$langs->trans("Printer")); +llxHeader("",$langs->trans("Printing")); -print_fiche_titre($langs->trans("Printer")); +print_fiche_titre($langs->trans("Printing")); -$printer = new dolPrintIPP($db,$conf->global->PRINTIPP_HOST,$conf->global->PRINTIPP_PORT,$user->login,$conf->global->PRINTIPP_USER,$conf->global->PRINTIPP_PASSWORD); -$printer->list_jobs('commande'); +// List Jobs from printing modules +//$printer = new dolPrintIPP($db,$conf->global->PRINTIPP_HOST,$conf->global->PRINTIPP_PORT,$user->login,$conf->global->PRINTIPP_USER,$conf->global->PRINTIPP_PASSWORD); +//$printer->list_jobs('commande'); llxFooter(); diff --git a/htdocs/printing/lib/index.html b/htdocs/printing/lib/index.html new file mode 100644 index 00000000000..e69de29bb2d diff --git a/htdocs/printipp/lib/printipp.lib.php b/htdocs/printing/lib/printing.lib.php similarity index 55% rename from htdocs/printipp/lib/printipp.lib.php rename to htdocs/printing/lib/printing.lib.php index 64c14609df5..1d09daba0dc 100644 --- a/htdocs/printipp/lib/printipp.lib.php +++ b/htdocs/printing/lib/printing.lib.php @@ -16,44 +16,54 @@ */ /** - * \file htdocs/printipp/lib/printipp.lib.php - * \ingroup printipp - * \brief Library for printipp functions + * \file htdocs/printing/lib/printing.lib.php + * \ingroup printing + * \brief Library for printing functions */ /** - * Define head array for tabs of printipp tools setup pages + * Define head array for tabs of printing tools setup pages * * @return Array of head */ -function printippadmin_prepare_head() +function printingadmin_prepare_head() { global $langs, $conf; $h = 0; $head = array(); - $head[$h][0] = DOL_URL_ROOT."/printipp/admin/printipp.php?mode=config"; - $head[$h][1] = $langs->trans("CupsServer"); + $head[$h][0] = DOL_URL_ROOT."/printing/admin/printing.php?mode=config"; + $head[$h][1] = $langs->trans("ListDrivers"); $head[$h][2] = 'config'; $h++; - $head[$h][0] = DOL_URL_ROOT."/printipp/admin/printipp.php?mode=test"; - $head[$h][1] = $langs->trans("Printer"); + $head[$h][0] = DOL_URL_ROOT."/printing/admin/printing.php?mode=setup"; + $head[$h][1] = $langs->trans("SetupDriver"); + $head[$h][2] = 'setup'; + $h++; + + $head[$h][0] = DOL_URL_ROOT."/printing/admin/printing.php?mode=test"; + $head[$h][1] = $langs->trans("TestDriver"); $head[$h][2] = 'test'; $h++; - $object=new stdClass(); + $head[$h][0] = DOL_URL_ROOT."/printing/admin/printing.php?mode=userconf"; + $head[$h][1] = $langs->trans("UserConf"); + $head[$h][2] = 'userconf'; + $h++; + + //$object=new stdClass(); // Show more tabs from modules // Entries must be declared in modules descriptor with line // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab // $this->tabs = array('entity:-tabname); to remove a tab - complete_head_from_modules($conf,$langs,$object,$head,$h,'printippadmin'); + //complete_head_from_modules($conf,$langs,$object,$head,$h,'printingadmin'); - complete_head_from_modules($conf,$langs,$object,$head,$h,'printipp','remove'); + //complete_head_from_modules($conf,$langs,$object,$head,$h,'printing','remove'); return $head; } diff --git a/htdocs/printipp/admin/printipp.php b/htdocs/printipp/admin/printipp.php deleted file mode 100644 index 28ad55453eb..00000000000 --- a/htdocs/printipp/admin/printipp.php +++ /dev/null @@ -1,246 +0,0 @@ - - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License 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 - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file htdocs/printipp/admin/printipp.php - * \ingroup printipp - * \brief Page to setup printipp module - */ - -require '../../main.inc.php'; - -require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/dolprintipp.class.php'; -require_once DOL_DOCUMENT_ROOT.'/printipp/lib/printipp.lib.php'; - -$langs->load("admin"); -$langs->load("printipp"); - -if (! $user->admin) accessforbidden(); - -$action = GETPOST('action','alpha'); -$mode = GETPOST('mode','alpha'); -$value = GETPOST('value','alpha'); - -if (!$mode) $mode='config'; - -/* - * Action - */ - -if ($action == 'setvalue' && $user->admin) -{ - $db->begin(); - - if (! $result > 0) $error++; - $result=dolibarr_set_const($db, "PRINTIPP_HOST",GETPOST('PRINTIPP_HOST','alpha'),'chaine',0,'',$conf->entity); - if (! $result > 0) $error++; - $result=dolibarr_set_const($db, "PRINTIPP_PORT",GETPOST('PRINTIPP_PORT','alpha'),'chaine',0,'',$conf->entity); - if (! $result > 0) $error++; - $result=dolibarr_set_const($db, "PRINTIPP_USER",GETPOST('PRINTIPP_USER','alpha'),'chaine',0,'',$conf->entity); - if (! $result > 0) $error++; - $result=dolibarr_set_const($db, "PRINTIPP_PASSWORD",GETPOST('PRINTIPP_PASSWORD','alpha'),'chaine',0,'',$conf->entity); - if (! $result > 0) $error++; - - if (! $error) - { - $db->commit(); - setEventMessage($langs->trans("SetupSaved")); - } - else - { - $db->rollback(); - dol_print_error($db); - } -} - -// Set default model -else if ($action == 'setprinteruri') -{ - if (dolibarr_set_const($db, "PRINTIPP_URI_DEFAULT",$value,'chaine',0,'',$conf->entity)) - { - // La constante qui a ete lue en avant du nouveau set - // on passe donc par une variable pour avoir un affichage coherent - $conf->global->PRINTIPP_URI_DEFAULT = $value; - } -} - - -/* - * View - */ - -$form = new Form($db); - -llxHeader('',$langs->trans("PrintIPPSetup")); - -$linkback=''.$langs->trans("BackToModuleList").''; -print_fiche_titre($langs->trans("PrintIPPSetup"),$linkback,'setup'); - -$head=printippadmin_prepare_head(); - - -if ($mode == 'config' && $user->admin) -{ - print '
'; - print ''; - print ''; - - dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"), 0, 'technic'); - - print $langs->trans("PrintIPPDesc")."

\n"; - - print ''; - - $var=true; - print ''; - print ''; - print ''; - print "\n"; - - /* - $var=!$var; - print ''; - */ - - $var=!$var; - print ''; - - $var=!$var; - print ''; - - $var=!$var; - print ''; - - $var=!$var; - print ''; - - //$var=true; - //print ''; - //print ''; - //print ''; - //print "\n"; - - print '
'.$langs->trans("Parameters").''.$langs->trans("Value").'
'; - print $langs->trans("PRINTIPP_ENABLED").''; - - if (! empty($conf->use_javascript_ajax)) - { - print ajax_constantonoff('PRINTIPP_ENABLED'); - } - else - { - if (empty($conf->global->PRINTIPP_ENABLED)) - { - print ''.img_picto($langs->trans("Disabled"),'off').''; - } - else - { - print ''.img_picto($langs->trans("Enabled"),'on').''; - } - } - print '
'; - print $langs->trans("PRINTIPP_HOST").''; - print ''; - print '   '.$langs->trans("Example").': localhost'; - print '
'; - print $langs->trans("PRINTIPP_PORT").''; - print ''; - print '   '.$langs->trans("Example").': 631'; - print '
'; - print $langs->trans("PRINTIPP_USER").''; - print ''; - print '
'; - print $langs->trans("PRINTIPP_PASSWORD").''; - print ''; - print '
'.$langs->trans("OtherParameter").''.$langs->trans("Value").'
'; - - dol_fiche_end(); - - print '
'; - - print ''; -} - -if ($mode == 'test' && $user->admin) -{ - dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"), 0, 'technic'); - - print $langs->trans("PrintIPPDesc")."

\n"; - - print ''; - $printer = new dolPrintIPP($db,$conf->global->PRINTIPP_HOST,$conf->global->PRINTIPP_PORT,$user->login,$conf->global->PRINTIPP_USER,$conf->global->PRINTIPP_PASSWORD); - $var=true; - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - //print ''; - print ''; - print ''; - print ''; - print "\n"; - - $list = $printer->getlist_available_printers(); - $var = true; - foreach ($list as $value) - { - $var=!$var; - $printer_det = $printer->get_printer_detail($value); - print ""; - print ''; - //print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - //print ''; - print ''; - print ''; - // Defaut - print "'; - print "\n"; - } - print '
UriNameStateState_reasonState_reason1BWColorDeviceMediaSupported'.$langs->trans("Select").'
'.$value.'
'.print_r($printer_det,true).'
'.$printer_det->printer_name->_value0.''.$printer_det->printer_state->_value0.''.$printer_det->printer_state_reasons->_value0.''.$printer_det->printer_state_reasons->_value1.''.$printer_det->printer_type->_value2.''.$printer_det->printer_type->_value3.''.$printer_det->device_uri->_value0.''.$printer_det->media_default->_value0.''.$printer_det->media_type_supported->_value1.'"; - if ($conf->global->PRINTIPP_URI_DEFAULT == "$value") - { - print img_picto($langs->trans("Default"),'on'); - } - else - { - print ''.img_picto($langs->trans("Disabled"),'off').''; - } - print '
'; - - if (count($list) == 0) print $langs->trans("NoPrinterFound"); - - dol_fiche_end(); -} - - - -llxFooter(); - -$db->close(); diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 294c8d1610e..a889136de01 100755 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -2812,33 +2812,27 @@ class Product extends CommonObject global $langs; $result=''; + $newref=$this->ref; + if ($maxlength) $newref=dol_trunc($newref,$maxlength,'middle'); + if ($this->type == 0) $label = $langs->trans("ShowProduct").': '.$this->ref.' '.$this->label; + if ($this->type == 1) $label = $langs->trans("ShowService").': '.$this->ref.' '.$this->label; + $linkclose = '" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; - if ($option == 'supplier') - { - $lien = ''; - $lienfin=''; - } - else if ($option == 'stock') - { - $lien = ''; + if ($option == 'supplier') { + $lien = ''; + } else if ($option == 'composition') { + $lien = ''; } - else if ($option == 'composition') - { - $lien = ''; - $lienfin=''; - } - else if ($option == 'category') - { - $lien = ''; - } - else - { - $lien = ''; - $lienfin=''; - } - $newref=$this->ref; - if ($maxlength) $newref=dol_trunc($newref,$maxlength,'middle'); if ($withpicto) { if ($this->type == 0) $result.=($lien.img_object($langs->trans("ShowProduct").' '.$this->label, 'product', 'class="classfortooltip"').$lienfin.' '); diff --git a/htdocs/product/document.php b/htdocs/product/document.php index 6ca92968e8d..e46dc0384b2 100644 --- a/htdocs/product/document.php +++ b/htdocs/product/document.php @@ -73,16 +73,20 @@ if ($id > 0 || ! empty($ref)) } $modulepart='produit'; + +/* + * Actions + */ + $parameters=array('id'=>$id); $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - -/* - * Action envoie fichier - */ - -include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; +if (empty($reshook)) +{ + // Action sending file + include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_pre_headers.tpl.php'; +} /* diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index 4f382d3b7f8..5adc79f3f65 100755 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -5,7 +5,7 @@ * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2010-2012 Juanjo Menent * Copyright (C) 2012 Christophe Battarel - * Copyright (C) 2014 Ion Agorria + * Copyright (C) 2014 Ion Agorria * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -81,151 +81,154 @@ $parameters=array('socid'=>$socid, 'id_prod'=>$id); $reshook=$hookmanager->executeHooks('doActions',$parameters,$product,$action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -if ($action == 'remove_pf') +if (empty($reshook)) { - $product = new ProductFournisseur($db); - if ($product->fetch($id) > 0) + if ($action == 'remove_pf') { - if ($rowid) + $product = new ProductFournisseur($db); + if ($product->fetch($id) > 0) { - $result=$product->remove_product_fournisseur_price($rowid); - $action = ''; - setEventMessage($langs->trans("PriceRemoved")); + if ($rowid) + { + $result=$product->remove_product_fournisseur_price($rowid); + $action = ''; + setEventMessage($langs->trans("PriceRemoved")); + } } } -} -if ($action == 'updateprice' && GETPOST('cancel') <> $langs->trans("Cancel")) -{ - $id_fourn=GETPOST("id_fourn"); - if (empty($id_fourn)) $id_fourn=GETPOST("search_id_fourn"); - $ref_fourn=GETPOST("ref_fourn"); - if (empty($ref_fourn)) $ref_fourn=GETPOST("search_ref_fourn"); - $quantity=GETPOST("qty"); - $remise_percent=price2num(GETPOST('remise_percent','alpha')); - $npr = preg_match('/\*/', $_POST['tva_tx']) ? 1 : 0 ; - $tva_tx = str_replace('*','', GETPOST('tva_tx','alpha')); - $tva_tx = price2num($tva_tx); - $price_expression = GETPOST('eid', 'int') == 0 ? 'NULL' : GETPOST('eid', 'int'); //Discard expression if not in expression mode + if ($action == 'updateprice' && GETPOST('cancel') <> $langs->trans("Cancel")) + { + $id_fourn=GETPOST("id_fourn"); + if (empty($id_fourn)) $id_fourn=GETPOST("search_id_fourn"); + $ref_fourn=GETPOST("ref_fourn"); + if (empty($ref_fourn)) $ref_fourn=GETPOST("search_ref_fourn"); + $quantity=GETPOST("qty"); + $remise_percent=price2num(GETPOST('remise_percent','alpha')); + $npr = preg_match('/\*/', $_POST['tva_tx']) ? 1 : 0 ; + $tva_tx = str_replace('*','', GETPOST('tva_tx','alpha')); + $tva_tx = price2num($tva_tx); + $price_expression = GETPOST('eid', 'int') == 0 ? 'NULL' : GETPOST('eid', 'int'); //Discard expression if not in expression mode - if ($tva_tx == '') - { - $error++; - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("VATRateForSupplierProduct")), 'errors'); - } - if (empty($quantity)) - { - $error++; - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Qty")), 'errors'); - } - if (empty($ref_fourn)) - { - $error++; - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("RefSupplier")), 'errors'); - } - if ($id_fourn <= 0) - { - $error++; - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Supplier")), 'errors'); - } - if ($_POST["price"] < 0 || $_POST["price"] == '') - { - if ($price_expression == 'NULL') { //This is not because of using expression instead of numeric price + if ($tva_tx == '') + { $error++; - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Price")), 'errors'); + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("VATRateForSupplierProduct")), 'errors'); } - else + if (empty($quantity)) { - $_POST["price"] = 0; + $error++; + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Qty")), 'errors'); + } + if (empty($ref_fourn)) + { + $error++; + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("RefSupplier")), 'errors'); + } + if ($id_fourn <= 0) + { + $error++; + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Supplier")), 'errors'); + } + if ($_POST["price"] < 0 || $_POST["price"] == '') + { + if ($price_expression == 'NULL') { //This is not because of using expression instead of numeric price + $error++; + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Price")), 'errors'); + } + else + { + $_POST["price"] = 0; + } + } + + $product = new ProductFournisseur($db); + $result=$product->fetch($id); + if ($result <= 0) + { + $error++; + setEventMessage($product->error, 'errors'); + } + + if (! $error) + { + $db->begin(); + + if (! $error) + { + $ret=$product->add_fournisseur($user, $id_fourn, $ref_fourn, $quantity); // This insert record with no value for price. Values are update later with update_buyprice + if ($ret == -3) + { + $error++; + + $product->fetch($product->product_id_already_linked); + $productLink = $product->getNomUrl(1,'supplier'); + + setEventMessage($langs->trans("ReferenceSupplierIsAlreadyAssociatedWithAProduct",$productLink), 'errors'); + } + else if ($ret < 0) + { + $error++; + setEventMessage($product->error, 'errors'); + } + } + + if (! $error) + { + $supplier=new Fournisseur($db); + $result=$supplier->fetch($id_fourn); + if (isset($_POST['ref_fourn_price_id'])) + $product->fetch_product_fournisseur_price($_POST['ref_fourn_price_id']); + + $ret=$product->update_buyprice($quantity, $_POST["price"], $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx, $_POST["charges"], $remise_percent, $npr); + if ($ret < 0) + { + + $error++; + setEventMessage($product->error, 'errors'); + } + else + { + if ($price_expression != 'NULL') { + //Check the expression validity by parsing it + $priceparser = new PriceParser($db); + $price_result = $priceparser->parseProductSupplier($id, $price_expression, $quantity, $tva_tx); + if ($price_result < 0) { //Expression is not valid + $error++; + setEventMessage($priceparser->translatedError(), 'errors'); + } + } + if (! $error && ! empty($conf->dynamicprices->enabled)) { + $ret=$product->setPriceExpression($price_expression); + if ($ret < 0) + { + $error++; + setEventMessage($product->error, 'errors'); + } + } + } + } + + if (! $error) + { + $db->commit(); + $action=''; + } + else + { + $db->rollback(); + } } } - $product = new ProductFournisseur($db); - $result=$product->fetch($id); - if ($result <= 0) + if (GETPOST('cancel') == $langs->trans("Cancel")) { - $error++; - setEventMessage($product->error, 'errors'); + $action = ''; + header("Location: fournisseurs.php?id=".$_GET["id"]); + exit; } - - if (! $error) - { - $db->begin(); - - if (! $error) - { - $ret=$product->add_fournisseur($user, $id_fourn, $ref_fourn, $quantity); // This insert record with no value for price. Values are update later with update_buyprice - if ($ret == -3) - { - $error++; - - $product->fetch($product->product_id_already_linked); - $productLink = $product->getNomUrl(1,'supplier'); - - setEventMessage($langs->trans("ReferenceSupplierIsAlreadyAssociatedWithAProduct",$productLink), 'errors'); - } - else if ($ret < 0) - { - $error++; - setEventMessage($product->error, 'errors'); - } - } - - if (! $error) - { - $supplier=new Fournisseur($db); - $result=$supplier->fetch($id_fourn); - if (isset($_POST['ref_fourn_price_id'])) - $product->fetch_product_fournisseur_price($_POST['ref_fourn_price_id']); - - $ret=$product->update_buyprice($quantity, $_POST["price"], $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx, $_POST["charges"], $remise_percent, $npr); - if ($ret < 0) - { - $error++; - setEventMessage($product->error, 'errors'); - } - else - { - if ($price_expression != 'NULL') { - //Check the expression validity by parsing it - $priceparser = new PriceParser($db); - $price_result = $priceparser->parseProductSupplier($id, $price_expression, $quantity, $tva_tx); - if ($price_result < 0) { //Expression is not valid - $error++; - setEventMessage($priceparser->translatedError(), 'errors'); - } - } - if (! $error && ! empty($conf->dynamicprices->enabled)) { - $ret=$product->setPriceExpression($price_expression); - if ($ret < 0) - { - $error++; - setEventMessage($product->error, 'errors'); - } - } - } - } - - if (! $error) - { - $db->commit(); - $action=''; - } - else - { - $db->rollback(); - } - } } -if (GETPOST('cancel') == $langs->trans("Cancel")) -{ - $action = ''; - header("Location: fournisseurs.php?id=".$_GET["id"]); - exit; -} - - /* * view @@ -398,7 +401,8 @@ if ($id || $ref) print ''; print ''; - if (! empty($conf->dynamicprices->enabled)) { //Only show price mode and expression selector if module is enabled + if (! empty($conf->dynamicprices->enabled)) //Only show price mode and expression selector if module is enabled + { // Price mode selector print ''.$langs->trans("PriceMode").''; $price_expression = new PriceExpression($db); @@ -456,7 +460,7 @@ if ($id || $ref) print ''; } } - + if (is_object($hookmanager)) { $parameters=array('id_fourn'=>$id_fourn,'prod_id'=>$product->id); @@ -467,7 +471,7 @@ if ($id || $ref) print '
'; print ''; - print '     '; + print '   '; print ''; print '
'; @@ -568,7 +572,7 @@ if ($id || $ref) // Charges ???? if ($conf->global->PRODUCT_CHARGES) - { + { if (! empty($conf->margin->enabled)) { print ''; @@ -576,7 +580,7 @@ if ($id || $ref) print ''; } } - + // Unit price print ''; print price($productfourn->fourn_unitprice); @@ -598,7 +602,7 @@ if ($id || $ref) print ''; } } - + if (is_object($hookmanager)) { $parameters=array('id_pfp'=>$productfourn->product_fourn_price_id,'id_fourn'=>$id_fourn,'prod_id'=>$product->id); diff --git a/htdocs/product/stock/class/entrepot.class.php b/htdocs/product/stock/class/entrepot.class.php index c0627015be3..3bfbbbffbcb 100644 --- a/htdocs/product/stock/class/entrepot.class.php +++ b/htdocs/product/stock/class/entrepot.class.php @@ -512,11 +512,12 @@ class Entrepot extends CommonObject global $langs; $result=''; + $label = $langs->trans("ShowStock").': '.$this->libelle; - $lien=''; - $lienfin=''; + $lien=''; + $lienfin=''; - if ($withpicto) $result.=($lien.img_object($langs->trans("ShowStock"), 'stock', 'class="classfortooltip"').$lienfin.' '); + if ($withpicto) $result.=($lien.img_object($label, 'stock', 'class="classfortooltip"').$lienfin.' '); $result.=$lien.$this->libelle.$lienfin; return $result; } diff --git a/htdocs/projet/card.php b/htdocs/projet/card.php index 1f6f430fccb..9b5f70e4dce 100644 --- a/htdocs/projet/card.php +++ b/htdocs/projet/card.php @@ -353,7 +353,8 @@ if (empty($reshook)) $clone_project_files = GETPOST('clone_project_files') ? 1 : 0; $clone_task_files = GETPOST('clone_task_files') ? 1 : 0; $clone_notes=GETPOST('clone_notes')?1:0; - $result=$object->createFromClone($object->id,$clone_contacts,$clone_tasks,$clone_project_files,$clone_task_files,$clone_notes); + $move_date=GETPOST('move_date')?1:0; + $result=$object->createFromClone($object->id,$clone_contacts,$clone_tasks,$clone_project_files,$clone_task_files,$clone_notes,$move_date); if ($result <= 0) { setEventMessage($object->error, 'errors'); @@ -538,6 +539,7 @@ else 'text' => $langs->trans("ConfirmClone"), array('type' => 'checkbox', 'name' => 'clone_contacts', 'label' => $langs->trans("CloneContacts"), 'value' => true), array('type' => 'checkbox', 'name' => 'clone_tasks', 'label' => $langs->trans("CloneTasks"), 'value' => true), + array('type' => 'checkbox', 'name' => 'move_date', 'label' => $langs->trans("CloneMoveDate"), 'value' => true), array('type' => 'checkbox', 'name' => 'clone_notes', 'label' => $langs->trans("CloneNotes"), 'value' => true), array('type' => 'checkbox', 'name' => 'clone_project_files','label' => $langs->trans("CloneProjectFiles"), 'value' => false), array('type' => 'checkbox', 'name' => 'clone_task_files', 'label' => $langs->trans("CloneTaskFiles"), 'value' => false) diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 5bf17d596a4..1d24076df27 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -416,13 +416,13 @@ class Project extends CommonObject { if (empty($datefieldname) && ! empty($this->table_element_date)) $datefieldname=$this->table_element_date; if (empty($datefieldname)) return 'Error this object has no date field defined'; - $sql.=" AND ".$datefieldname." >= '".$this->db->idate($dates)."'"; + $sql.=" AND (".$datefieldname." >= '".$this->db->idate($dates)."' OR ".$datefieldname." IS NULL)"; } if ($datee > 0) { if (empty($datefieldname) && ! empty($this->table_element_date)) $datefieldname=$this->table_element_date; if (empty($datefieldname)) return 'Error this object has no date field defined'; - $sql.=" AND ".$datefieldname." <= '".$this->db->idate($datee)."'"; + $sql.=" AND (".$datefieldname." <= '".$this->db->idate($datee)."' OR ".$datefieldname." IS NULL)"; } if (! $sql) return -1; @@ -789,25 +789,22 @@ class Project extends CommonObject $result = ''; $lien = ''; $lienfin = ''; + $label = $langs->trans("ShowProject") . ': ' . $this->ref . ($this->title ? ' - ' . $this->title : ''); + $linkclose = '" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; - if ($option != 'nolink') - { - if (preg_match('/\.php$/',$option)) - { - $lien = ''; - $lienfin = ''; - } - else - { - $lien = ''; - $lienfin = ''; - } + if ($option != 'nolink') { + if (preg_match('/\.php$/',$option)) { + $lien = ''; + } } $picto = 'projectpub'; if (!$this->public) $picto = 'project'; - $label = $langs->trans("ShowProject") . ': ' . $this->ref . ($this->title ? ' - ' . $this->title : ''); if ($withpicto) $result.=($lien . img_object($label, $picto, 'class="classfortooltip"') . $lienfin); if ($withpicto && $withpicto != 2) $result.=' '; @@ -1002,16 +999,17 @@ class Project extends CommonObject * @param bool $clone_project_file clone file of project * @param bool $clone_task_file clone file of task (if task are copied) * @param bool $clone_note clone note of project + * @param bool $move_date move task date on clone * @param bool $notrigger no trigger flag * @return int New id of clone */ - function createFromClone($fromid,$clone_contact=false,$clone_task=true,$clone_project_file=false,$clone_task_file=false,$clone_note=true,$notrigger=0) + function createFromClone($fromid,$clone_contact=false,$clone_task=true,$clone_project_file=false,$clone_task_file=false,$clone_note=true,$move_date=true,$notrigger=0) { global $user,$langs,$conf; $error=0; - dol_syslog("createFromClone clone_contact=".$clone_contact." clone_task=".$clone_task." clone_project_file=".$clone_project_file." clone_note=".$clone_note); + dol_syslog("createFromClone clone_contact=".$clone_contact." clone_task=".$clone_task." clone_project_file=".$clone_project_file." clone_note=".$clone_note." move_date=".$move_date,LOG_DEBUG); $now = dol_mktime(0,0,0,idate('m',dol_now()),idate('d',dol_now()),idate('Y',dol_now())); @@ -1027,11 +1025,13 @@ class Project extends CommonObject $orign_project_ref=$clone_project->ref; $clone_project->id=0; - $clone_project->date_start = $now; - if (!(empty($clone_project->date_end))) - { - $clone_project->date_end = $clone_project->date_end + ($now - $orign_dt_start); - } + if ($move_date) { + $clone_project->date_start = $now; + if (!(empty($clone_project->date_end))) + { + $clone_project->date_end = $clone_project->date_end + ($now - $orign_dt_start); + } + } $clone_project->datec = $now; @@ -1185,7 +1185,7 @@ class Project extends CommonObject foreach ($tasksarray as $tasktoclone) { - $result_clone = $taskstatic->createFromClone($tasktoclone->id,$clone_project_id,$tasktoclone->fk_parent,true,true,false,$clone_task_file,true,false); + $result_clone = $taskstatic->createFromClone($tasktoclone->id,$clone_project_id,$tasktoclone->fk_parent,$move_date,true,false,$clone_task_file,true,false); if ($result_clone <= 0) { $this->error.=$result_clone->error; diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index 786caafb7ec..5dde5e21b88 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -505,13 +505,13 @@ class Task extends CommonObject global $langs; $result=''; + $label=$langs->trans("ShowTask").': '.$this->ref.($this->label?' - '.$this->label:''); - $lien = ''; + $lien = ''; $lienfin=''; $picto='projecttask'; - $label=$langs->trans("ShowTask").': '.$this->ref.($this->label?' - '.$this->label:''); if ($withpicto) $result.=($lien.img_object($label, $picto, 'class="classfortooltip"').$lienfin); if ($withpicto && $withpicto != 2) $result.=' '; diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index bc7478a0dbb..39195ae3de3 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -145,12 +145,12 @@ print ''.$langs->trans("Status").''.$project->getLibStatut(4).' // Date start print ''.$langs->trans("DateStart").''; -print dol_print_date($object->date_start,'day'); +print dol_print_date($project->date_start,'day'); print ''; // Date end print ''.$langs->trans("DateEnd").''; -print dol_print_date($object->date_end,'day'); +print dol_print_date($project->date_end,'day'); print ''; print ''; @@ -275,7 +275,7 @@ foreach ($listofreferent as $key => $value) { print '
'; print ''; - print ''; + print ''; print ''; //print ''; print '\n"; // Date - $date=$element->date; - if (empty($date)) $date=$element->datep; - if (empty($date)) $date=$element->date_contrat; - if (empty($date)) $date=$element->datev; //Fiche inter + if ($tablename == 'commande_fournisseur' || $tablename == 'supplier_order') $date=$element->date_commande; + else + { + $date=$element->date; + if (empty($date)) $date=$element->datep; + if (empty($date)) $date=$element->date_contrat; + if (empty($date)) $date=$element->datev; //Fiche inter + } print ''; // Third party print ''; - // Amount + // Amount without tax if (empty($value['disableamount'])) { print ''; - // Amount + // Amount inc tax if (empty($value['disableamount'])) { print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $total_ht_by_third = 0; + $total_ttc_by_third = 0; + $var=true; + } } } @@ -533,3 +576,63 @@ print "
'.$langs->trans("Filter").':'.$langs->trans("From").' '; @@ -331,6 +331,15 @@ foreach ($listofreferent as $key => $value) $var=true; $total_ht = 0; $total_ttc = 0; + + $total_ht_by_third = 0; + $total_ttc_by_third = 0; + + if (canApplySubtotalOn($tablename)) { + // Appel du mon code de tri : + $elementarray = sortElementsByClientName($elementarray); + } + $num=count($elementarray); for ($i = 0; $i < $num; $i++) { @@ -356,18 +365,22 @@ foreach ($listofreferent as $key => $value) print "'.dol_print_date($date,'day').''; - if (is_object($element->client)) print $element->client->getNomUrl(1,'',48); + if (is_object($element->thirdparty)) print $element->thirdparty->getNomUrl(1,'',48); print ''; @@ -378,7 +391,7 @@ foreach ($listofreferent as $key => $value) } else print ''; @@ -398,6 +411,36 @@ foreach ($listofreferent as $key => $value) { $total_ht = $total_ht + $element->total_ht; $total_ttc = $total_ttc + $element->total_ttc; + + $total_ht_by_third += $element->total_ht; + $total_ttc_by_third += $element->total_ttc; + } + + // Autre partie de mon code : + if (canApplySubtotalOn($tablename)) + { + $next_third_id = (isset($elementarray[$i+1])) ? $elementarray[$i+1] : ''; + $third_id = $element->thirdparty->id; + if ($third_id != $next_third_id) + { + print '
'; + print ''; + print ''; + print $langs->trans('SubTotal').' : '; + if (is_object($element->thirdparty)) print $element->thirdparty->getNomUrl(0,'',48); + print ''.price($total_ht).''.price($total_ttc).'
"; llxFooter(); $db->close(); + + + +/** + * Return if we should do a group by customer with sub-total + * + * @param string $tablename Name of table + * @return boolean True to tell to make a group by sub-total + */ +function canApplySubtotalOn($tablename) +{ + global $conf; + + if (empty($conf->global->PROJECT_ADD_SUBTOTAL_LINES)) return false; + return in_array($tablename, array('facture_fourn', 'commande_fournisseur')); +} + +/** + * getClientName + * + * @param unknown_type $id + */ +function getClientName($id) { + global $db, $classname; + $element = new $classname($db); + $element->fetch($id); + $element->fetch_thirdparty(); + return $element->thirdparty->name; +} + +/** + * getClientNameArray + * + * @param unknown_type $elementarray + */ +function getClientNameArray($elementarray) { + $clientname = array(); + foreach ($elementarray as $key => $id) { + $clientname[$id] = getClientName($id); + } + return $clientname; +} + +/** + * sortElementsByClientName + * + * @param unknown_type $elementarray + */ +function sortElementsByClientName($elementarray) { + $clientname = getClientNameArray($elementarray); + asort($clientname); + + $elementarray = array(); + foreach ($clientname as $id => $name) { + $elementarray[] = $id; + } + + return $elementarray; +} + diff --git a/htdocs/public/agenda/agendaexport.php b/htdocs/public/agenda/agendaexport.php index c36766e2777..2b1d02ef493 100644 --- a/htdocs/public/agenda/agendaexport.php +++ b/htdocs/public/agenda/agendaexport.php @@ -69,7 +69,6 @@ if (! empty($_GET["project"])) $filters['project']=$_GET["project"]; if (! empty($_GET["login"])) $filters['login']=$_GET["login"]; if (! empty($_GET["logina"])) $filters['logina']=$_GET["logina"]; if (! empty($_GET["logint"])) $filters['logint']=$_GET["logint"]; -if (! empty($_GET["logind"])) $filters['logind']=$_GET["logind"]; // Not older than if (! isset($conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY)) $conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY=100; $filters['notolderthan']=$conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY; @@ -111,8 +110,7 @@ foreach ($filters as $key => $value) if ($key == 'project') $filename.='-project'.$value; if ($key == 'login') $filename.='-login'.$value; if ($key == 'logina') $filename.='-logina'.$value; // Author - if ($key == 'logind') $filename.='-logind'.$value; // Affected to - if ($key == 'logint') $filename.='-logint'.$value; // Done by + if ($key == 'logint') $filename.='-logint'.$value; // Assigned to } // Add extension if ($format == 'vcal') { $shortfilename.='.vcs'; $filename.='.vcs'; } diff --git a/htdocs/public/test/test_arrays.php b/htdocs/public/test/test_arrays.php index 6725c776cd4..5ff161f0b1a 100644 --- a/htdocs/public/test/test_arrays.php +++ b/htdocs/public/test/test_arrays.php @@ -4,11 +4,14 @@ define("NOCSRFCHECK",1); // We accept to go on this page from external web site. require '../../main.inc.php'; -if ($_SERVER['HTTP_HOST'] != 'localhost') + +if ($_SERVER['REMOTE_ADDR'] != '127.0.0.1') { - print "Page available only with url http://localhost/..."; + print "Page available only frome remote address 127.0.0.1"; exit; } + + $usedolheader=0; // 1 = Test inside a dolibarr page, 0 = Use hard coded header diff --git a/htdocs/public/test/test_forms.php b/htdocs/public/test/test_forms.php index 55b8296e43a..ece0c218160 100644 --- a/htdocs/public/test/test_forms.php +++ b/htdocs/public/test/test_forms.php @@ -6,9 +6,9 @@ define('REQUIRE_JQUERY_MULTISELECT','select2'); require '../../main.inc.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; -if ($_SERVER['HTTP_HOST'] != 'localhost') +if ($_SERVER['REMOTE_ADDR'] != '127.0.0.1') { - print "Page available only with url http://localhost/..."; + print "Page available only frome remote address 127.0.0.1"; exit; } diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php index 33a27796aaf..0863cad9c52 100644 --- a/htdocs/resource/card.php +++ b/htdocs/resource/card.php @@ -62,58 +62,57 @@ $parameters=array('resource_id'=>$id); $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - -/******************************************************************* -* ACTIONS -* -* Put here all code to do according to value of "action" parameter -********************************************************************/ - -if ($action == 'update' && ! $_POST["cancel"] && $user->rights->resource->write ) +if (empty($reshook)) { - $error=0; + /******************************************************************* + * ACTIONS + ********************************************************************/ - if (empty($ref)) + if ($action == 'update' && ! $_POST["cancel"] && $user->rights->resource->write ) { - $error++; - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")).'
'; - } + $error=0; - if (! $error) - { - $res = $object->fetch($id); - if ( $res > 0 ) + if (empty($ref)) { - $object->ref = $ref; - $object->description = $description; - $object->fk_code_type_resource = $fk_code_type_resource; + $error++; + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")), 'errors'); + } - $result=$object->update($user); - if ($result > 0) + if (! $error) + { + $res = $object->fetch($id); + if ( $res > 0 ) { - Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; + $object->ref = $ref; + $object->description = $description; + $object->fk_code_type_resource = $fk_code_type_resource; + + $result=$object->update($user); + if ($result > 0) + { + Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } + else + { + setEventMessage($object->error, 'errors'); + $action='edit'; + } + } else { - setEventMessage('
'.$object->error.'
'); + setEventMessage($object->error,'errors'); $action='edit'; } - } else { - setEventMessage($object->error,'errors'); $action='edit'; } } - else - { - $action='edit'; - } } - /*************************************************** * VIEW * diff --git a/htdocs/resource/class/resource.class.php b/htdocs/resource/class/resource.class.php index deea00f9c99..498291c1cc1 100644 --- a/htdocs/resource/class/resource.class.php +++ b/htdocs/resource/class/resource.class.php @@ -869,10 +869,11 @@ class Resource extends CommonObject global $langs; $result=''; + $label=$langs->trans("ShowResource").': '.$this->ref; if ($option == '') { - $lien = ''; + $lien = ''; $picto='resource@resource'; $label=$langs->trans("ShowResource").': '.$this->ref; @@ -880,7 +881,6 @@ class Resource extends CommonObject $lienfin=''; - $label=$langs->trans("ShowResource").': '.$this->ref; if ($withpicto) $result.=($lien.img_object($label, $picto, 'class="classfortooltip"').$lienfin); if ($withpicto && $withpicto != 2) $result.=' '; diff --git a/htdocs/societe/agenda.php b/htdocs/societe/agenda.php index 8d731875442..a6ba3d7b1cf 100644 --- a/htdocs/societe/agenda.php +++ b/htdocs/societe/agenda.php @@ -59,9 +59,6 @@ $contactstatic = new Contact($db); $form = new Form($db); -/* - * Fiche categorie de client et/ou fournisseur - */ if ($socid) { require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; @@ -70,79 +67,79 @@ if ($socid) $langs->load("companies"); - $soc = new Societe($db); - $result = $soc->fetch($socid); + $object = new Societe($db); + $result = $object->fetch($socid); llxHeader("",$langs->trans("Agenda"),''); if (! empty($conf->notification->enabled)) $langs->load("mails"); - $head = societe_prepare_head($soc); + $head = societe_prepare_head($object); dol_fiche_head($head, 'agenda', $langs->trans("ThirdParty"),0,'company'); print ''; print ''; if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field { - print ''; + print ''; } - if ($soc->client) + if ($object->client) { print ''; } - if ($soc->fournisseur) + if ($object->fournisseur) { print ''; } if (! empty($conf->barcode->enabled)) { - print ''; + print ''; } print ""; // Zip / Town - print '"; - print '"; + print '"; + print '"; // Country - if ($soc->country) { + if ($object->country) { print ''; } // EMail print ''; // Web print ''; // Phone / Fax - print ''; - print ''; + print ''; + print ''; print '
'.$langs->trans("ThirdPartyName").''; - print $form->showrefnav($soc,'socid','',($user->societe_id?0:1),'rowid','nom'); + print $form->showrefnav($object,'socid','',($user->societe_id?0:1),'rowid','nom'); print '
'.$langs->trans('Prefix').''.$soc->prefix_comm.'
'.$langs->trans('Prefix').''.$object->prefix_comm.'
'; print $langs->trans('CustomerCode').''; - print $soc->code_client; - if ($soc->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')'; + print $object->code_client; + if ($object->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')'; print '
'; print $langs->trans('SupplierCode').''; - print $soc->code_fournisseur; - if ($soc->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')'; + print $object->code_fournisseur; + if ($object->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')'; print '
'.$langs->trans('Gencod').''.$soc->barcode.'
'.$langs->trans('Gencod').''.$object->barcode.'
".$langs->trans('Address').""; - dol_print_address($soc->address, 'gmap', 'thirdparty', $soc->id); + dol_print_address($object->address, 'gmap', 'thirdparty', $object->id); print "
'.$langs->trans('Zip').''.$soc->zip."'.$langs->trans('Town').''.$soc->town."
'.$langs->trans('Zip').''.$object->zip."'.$langs->trans('Town').''.$object->town."
'.$langs->trans('Country').''; - $img=picto_from_langcode($soc->country_code); + $img=picto_from_langcode($object->country_code); print ($img?$img.' ':''); - print $soc->country; + print $object->country; print '
'.$langs->trans('EMail').''; - print dol_print_email($soc->email,0,$soc->id,'AC_EMAIL'); + print dol_print_email($object->email,0,$object->id,'AC_EMAIL'); print '
'.$langs->trans('Web').''; - print dol_print_url($soc->url); + print dol_print_url($object->url); print '
'.$langs->trans('Phone').''.dol_print_phone($soc->phone,$soc->country_code,0,$soc->id,'AC_TEL').''.$langs->trans('Fax').''.dol_print_phone($soc->fax,$soc->country_code,0,$soc->id,'AC_FAX').'
'.$langs->trans('Phone').''.dol_print_phone($object->phone,$object->country_code,0,$object->id,'AC_TEL').''.$langs->trans('Fax').''.dol_print_phone($object->fax,$object->country_code,0,$object->id,'AC_FAX').'
'; @@ -171,7 +168,7 @@ if ($socid) print '
'; - $objthirdparty=$soc; + $objthirdparty=$object; $objcon=new stdClass(); $out=''; @@ -189,10 +186,10 @@ if ($socid) print load_fiche_titre($langs->trans("ActionsOnCompany"),$out,''); // List of todo actions - show_actions_todo($conf,$langs,$db,$soc); + show_actions_todo($conf,$langs,$db,$object); // List of done actions - show_actions_done($conf,$langs,$db,$soc); + show_actions_done($conf,$langs,$db,$object); } diff --git a/htdocs/societe/class/address.class.php b/htdocs/societe/class/address.class.php index 55511922385..06be3f501fb 100644 --- a/htdocs/societe/class/address.class.php +++ b/htdocs/societe/class/address.class.php @@ -422,8 +422,9 @@ class Address global $langs; $result=''; + $label = $langs->trans("ShowAddress").': '.$this->label; - $lien = ''; + $lien = ''; $lienfin=''; if ($withpicto) $result.=($lien.img_object($langs->trans("ShowAddress").': '.$this->label, 'address', 'class="classfortooltip"').$lienfin.' '); diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 8f2e64874c6..4ce603ee1ad 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1749,7 +1749,7 @@ class Societe extends CommonObject } // Add type of canvas - $lien.=(!empty($this->canvas)?'&canvas='.$this->canvas:'').'">'; + $lien.=(!empty($this->canvas)?'&canvas='.$this->canvas:'').'" title="'.dol_escape_htmltag($name, 1).'" class="classfortooltip">'; $lienfin=''; if ($withpicto) $result.=($lien.img_object($langs->trans("ShowCompany").': '.$name, 'company', 'class="classfortooltip"').$lienfin); @@ -1999,6 +1999,8 @@ class Societe extends CommonObject { $contact_property=''; + if (empty($rowid)) return ''; + $sql = "SELECT rowid, email, phone_mobile, lastname, firstname"; $sql.= " FROM ".MAIN_DB_PREFIX."socpeople"; $sql.= " WHERE rowid = '".$rowid."'"; diff --git a/htdocs/societe/consumption.php b/htdocs/societe/consumption.php index f8b5829b03e..d8aad10d054 100644 --- a/htdocs/societe/consumption.php +++ b/htdocs/societe/consumption.php @@ -67,7 +67,7 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both } // Customer or supplier selected in drop box $thirdTypeSelect = GETPOST("third_select_id"); -$type_element = GETPOST('type_element')?GETPOST('type_element'):$type_element; +$type_element = GETPOST('type_element')?GETPOST('type_element'):''; $langs->load("companies"); diff --git a/htdocs/societe/info.php b/htdocs/societe/info.php index 305936e6f56..9d06d203d9c 100644 --- a/htdocs/societe/info.php +++ b/htdocs/societe/info.php @@ -59,21 +59,21 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; llxHeader('',$langs->trans("ThirdParty"),$help_url); -$soc = new Societe($db); -$soc->fetch($socid); -$soc->info($socid); +$object = new Societe($db); +$object->fetch($socid); +$object->info($socid); /* * Affichage onglets */ -$head = societe_prepare_head($soc); +$head = societe_prepare_head($object); dol_fiche_head($head, 'info', $langs->trans("ThirdParty"),0,'company'); print '
'; -dol_print_object_info($soc); +dol_print_object_info($object); print '
'; diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index 656e88ec83c..5cde8eb572a 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -106,7 +106,6 @@ if (empty($reshook)) { //obtidre selected del combobox $value=GETPOST('lt1'); - $object = new Societe($db); $object->fetch($socid); $res=$object->setValueFrom('localtax1_value', $value); } @@ -114,7 +113,6 @@ if (empty($reshook)) { //obtidre selected del combobox $value=GETPOST('lt2'); - $object = new Societe($db); $object->fetch($socid); $res=$object->setValueFrom('localtax2_value', $value); } @@ -583,14 +581,22 @@ if (empty($reshook)) * View */ -$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; -llxHeader('',$langs->trans("ThirdParty"),$help_url); - $form = new Form($db); $formfile = new FormFile($db); $formadmin = new FormAdmin($db); $formcompany = new FormCompany($db); +if ($socid > 0 && empty($object->id)) +{ + $res=$object->fetch($socid); + if ($result <= 0) dol_print_error('',$object->error); +} + +$title=$langs->trans("ThirdParty"); +if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name; +$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; +llxHeader('',$title,$help_url); + $countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')'; if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) @@ -598,12 +604,6 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) // ----------------------------------------- // When used with CANVAS // ----------------------------------------- - if (empty($object->error) && $socid) - { - $object = new Societe($db); - $result=$object->fetch($socid); - if ($result <= 0) dol_print_error('',$object->error); - } $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates $objcanvas->display_canvas($action); // Show template } @@ -1111,9 +1111,6 @@ else if ($socid) { - $object = new Societe($db); - $res=$object->fetch($socid); - if ($res < 0) { dol_print_error($db,$object->error); exit; } $res=$object->fetch_optionals($object->id,$extralabels); //if ($res < 0) { dol_print_error($db); exit; } @@ -1624,9 +1621,6 @@ else /* * View */ - $object = new Societe($db); - $res=$object->fetch($socid); - if ($res < 0) { dol_print_error($db,$object->error); exit; } $res=$object->fetch_optionals($object->id,$extralabels); //if ($res < 0) { dol_print_error($db); exit; } @@ -1751,7 +1745,8 @@ else print ''.$langs->trans("Country").''; if (! empty($object->country_code)) { - $img=picto_from_langcode($object->country_code); + //$img=picto_from_langcode($object->country_code); + $img=''; if ($object->isInEEC()) print $form->textwithpicto(($img?$img.' ':'').$object->country,$langs->trans("CountryIsInEEC"),1,0); else print ($img?$img.' ':'').$object->country; } diff --git a/htdocs/theme/eldy/img/menus/README.md b/htdocs/theme/eldy/img/menus/README.md new file mode 100644 index 00000000000..1b3942d1913 --- /dev/null +++ b/htdocs/theme/eldy/img/menus/README.md @@ -0,0 +1,12 @@ + +Tutorial to create a new image for menu: + +1) First find an image. +2) With Gimp, open image and check there is a alpha channel. If not add one. +3) Convert image into back and white. +4) Use the degrade tool with option: +* Erase color +* Opacity: 50 +/- +* Offset: 0 +* Shape: Linear +Il est possible aussi d'augmenter la transparence globale depuis le calque. diff --git a/htdocs/theme/eldy/img/menus/chart.png b/htdocs/theme/eldy/img/menus/chart.png new file mode 100644 index 00000000000..6efce90a788 Binary files /dev/null and b/htdocs/theme/eldy/img/menus/chart.png differ diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index bb5941c8130..a6d492aa9c4 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -532,8 +532,8 @@ margin : 0px auto; div#tmenu_tooltip { @@ -679,7 +679,7 @@ div.mainmenu { position : relative; background-repeat:no-repeat; background-position:center top; - height: px; + height: px; margin-left: 0px; min-width: 40px; } @@ -704,16 +704,10 @@ div.mainmenu.bank { background-image: url(); } -div.mainmenu.bookmark { -} - div.mainmenu.cashdesk { background-image: url(); } -div.mainmenu.click2dial { -} - div.mainmenu.companies { background-image: url(); } @@ -734,12 +728,6 @@ div.mainmenu.ftp { background-image: url(); } -div.mainmenu.gravatar { -} - -div.mainmenu.geopipmaxmind { -} - div.mainmenu.hrm { background-image: url(); } @@ -748,9 +736,6 @@ div.mainmenu.members { background-image: url(); } -div.mainmenu.paypal { -} - div.mainmenu.products { background-image: url(); margin-left: 10px; @@ -764,14 +749,6 @@ div.mainmenu.tools { background-image: url(); } -div.mainmenu.webservices { -} - -div.mainmenu.google { - background-image: url(); -} - - 'name of class for div') @@ -2443,6 +2420,11 @@ li.cal_event { border: none; list-style-type: none; } .cal_event a:active { color: #111111; font-size: 11px; font-weight: normal !important; } .cal_event a:hover { color: #111111; font-size: 11px; font-weight: normal !important; color:rgba(255,255,255,.75); } .cal_event_busy { } +.cal_peruserviewname { max-width: 100px; height: 22px; } + +.topmenuimage { + background-size: 28px auto; +} /* ============================================================================== */ /* Ajax - Liste deroulante de l'autocompletion */ diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 9ea4f3de9c5..11eaa8afb45 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -1786,14 +1786,14 @@ class User extends CommonObject global $langs; $result=''; + $label = $langs->trans("ShowUser").': '.$this->getFullName($langs,'','',24); - $lien = ''; + $lien = ''; $lienfin=''; - if ($withpicto) - { - $result.=($lien.img_object($langs->trans("ShowUser"), 'user', 'class="classfortooltip"').$lienfin); - if ($withpicto != 2) $result.=' '; + if ($withpicto) { + $result.=($lien.img_object($label, 'user', 'class="classfortooltip"').$lienfin); + if ($withpicto != 2) $result.=' '; } $result.=$lien.$this->getFullName($langs,'','',24).$lienfin; return $result; diff --git a/htdocs/user/class/usergroup.class.php b/htdocs/user/class/usergroup.class.php index 5ff1a928d1c..599172c028e 100644 --- a/htdocs/user/class/usergroup.class.php +++ b/htdocs/user/class/usergroup.class.php @@ -189,7 +189,7 @@ class UserGroup extends CommonObject * * @param string $excludefilter Filter to exclude * @param int $mode 0=Return array of user instance, 1=Return array of users id only - * @return array Array of users + * @return mixed Array of users or -1 on error */ function listUsersForGroup($excludefilter='', $mode=0) { diff --git a/scripts/accountancy/export-thirdpartyaccount.php b/scripts/accountancy/export-thirdpartyaccount.php index 2556457f38e..f1ff769059c 100755 --- a/scripts/accountancy/export-thirdpartyaccount.php +++ b/scripts/accountancy/export-thirdpartyaccount.php @@ -164,7 +164,6 @@ if ($resql) { header('Content-Disposition: attachment;filename=export_csv.csv'); $obj = $db->fetch_object($resql); - $var = ! $var; print '"' . $obj->compta . '",'; print '"' . $obj->address . '",'; @@ -237,4 +236,4 @@ if ($resql) { } llxFooter(); -$db->close(); \ No newline at end of file +$db->close(); diff --git a/scripts/emailings/mailing-send.php b/scripts/emailings/mailing-send.php index 1de66b491ed..e7b32b2d3bc 100755 --- a/scripts/emailings/mailing-send.php +++ b/scripts/emailings/mailing-send.php @@ -245,6 +245,11 @@ if ($resql) $error++; } } + + if (!empty($conf->global->MAILING_DELAY)) { + sleep($conf->global->MAILING_DELAY); + } + } } else diff --git a/scripts/odt2pdf/odt2pdf.sh b/scripts/odt2pdf/odt2pdf.sh index 9d9bf18a8c7..c7c768a1244 100755 --- a/scripts/odt2pdf/odt2pdf.sh +++ b/scripts/odt2pdf/odt2pdf.sh @@ -1,8 +1,12 @@ #!/bin/bash # @copyright GPL License 2010 - Vikas Mahajan - http://vikasmahajan.wordpress.com # @copyright GPL License 2013 - Florian HEnry - florian.henry@open-concept.pro - # +# Convert an ODT into a PDF using "jodconverter" tool. +# Dolibarr variable MAIN_ODT_AS_PDF must be defined to have this script called after ODT generation. +# Dolibarr variable MAIN_DOL_SCRIPTS_ROOT must be defined to path of script directories (otherwise dolibarr will try to guess). + + #if [ -f "$1.odt" ] # then # soffice --invisible --convert-to pdf:writer_pdf_Export --outdir $2 "$1.odt" diff --git a/test/phpunit/FactureTest.php b/test/phpunit/FactureTest.php index c68014e9606..3248be7104c 100644 --- a/test/phpunit/FactureTest.php +++ b/test/phpunit/FactureTest.php @@ -216,7 +216,7 @@ class FactureTest extends PHPUnit_Framework_TestCase $newlocalobject=new Facture($this->savdb); $newlocalobject->initAsSpecimen(); $this->changeProperties($newlocalobject); - $this->assertEquals($this->objCompare($localobject,$newlocalobject,true,array('newref','oldref','id','lines','client','thirdparty','brouillon','user_author','date_creation','date_validation','datem','ref','statut','paye','specimen','facnumber','actiontypecode','actionmsg2','actionmsg','mode_reglement','cond_reglement','cond_reglement_doc')), array()); // Actual, Expected + $this->assertEquals($this->objCompare($localobject,$newlocalobject,true,array('newref','oldref','id','lines','client','thirdparty','brouillon','user_author','date_creation','date_validation','datem','ref','statut','paye','specimen','facnumber','actiontypecode','actionmsg2','actionmsg','mode_reglement','cond_reglement','cond_reglement_doc','situation_cycle_ref','situation_counter','situation_final')), array()); // Actual, Expected return $localobject; } diff --git a/test/phpunit/NumberingModulesTest.php b/test/phpunit/NumberingModulesTest.php index 043b8ae5a83..904c102e0a8 100644 --- a/test/phpunit/NumberingModulesTest.php +++ b/test/phpunit/NumberingModulesTest.php @@ -167,7 +167,7 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase $this->assertEquals(1, $result); // Can be deleted $result=$localobject->is_erasable(); print __METHOD__." is_erasable=".$result."\n"; - $this->assertEquals(0, $result, 'Test for {yyyy}-{0000} that is_erasable is 0 for 1st invoice'); // 1 can no more be deleted (2 is more recent + $this->assertEquals(0, $result, 'Test for {yyyy}-{0000} that is_erasable is 0 for 1st invoice'); // 1 can no more be deleted (2 is more recent) // Now we try with a reset $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}-{0000@1}'; @@ -502,7 +502,7 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase $conf->global->SOCIETE_FISCAL_MONTH_START=6; $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@99}'; $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000@99}'; - + $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1980); // we use year 1980 to be sure to not have existing invoice for this year @@ -512,7 +512,7 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase $result3=$localobject->validate($user, $result); print __METHOD__." result=".$result."\n"; $this->assertEquals('198001-0001', $result); // counter must start to 1 - + $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1980); // we use year 1980 to be sure to not have existing invoice for this year @@ -522,7 +522,7 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase $result3=$localobject->validate($user, $result); print __METHOD__." result=".$result."\n"; $this->assertEquals('198001-0002', $result); // counter must start to 2 - + $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); $localobject->date=dol_mktime(12, 0, 0, 2, 1, 1980); // we use year 1980 to be sure to not have existing invoice for this year @@ -532,7 +532,7 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase $result3=$localobject->validate($user, $result); print __METHOD__." result=".$result."\n"; $this->assertEquals('198002-0001', $result); // counter must start to 1 - + $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1981); // we use year 1981 to be sure to not have existing invoice for this year @@ -542,7 +542,28 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase $result3=$localobject->validate($user, $result); print __METHOD__." result=".$result."\n"; $this->assertEquals('198101-0001', $result); // counter must start to 1 - + + // Test with {t} tag + $conf->global->SOCIETE_FISCAL_MONTH_START=1; + $conf->global->FACTURE_MERCURE_MASK_CREDIT='{t}{yyyy}{mm}-{0000}'; + $conf->global->FACTURE_MERCURE_MASK_INVOICE='{t}{yyyy}{mm}-{0000}'; + + $tmpthirdparty=new Societe($this->savdb); + $tmpthirdparty->initAsSpecimen(); + $tmpthirdparty->typent_code = 'TE_ABC'; + + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1982); // we use year 1982 to be sure to not have existing invoice for this year + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($tmpthirdparty, $localobject); + $result2=$localobject->create($user,1); + $result3=$localobject->validate($user, $result); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('A198201-0001', $result); // counter must start to 1 + + + return $result; } diff --git a/test/phpunit/PricesTest.php b/test/phpunit/PricesTest.php index c01a3701177..9b46f8cc1d6 100755 --- a/test/phpunit/PricesTest.php +++ b/test/phpunit/PricesTest.php @@ -1,20 +1,20 @@ * -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License 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 -* GNU General Public License for more details. -* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License 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 + * GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * or see http://www.gnu.org/ -*/ + */ /** * \file test/phpunit/PricesTest.php @@ -215,9 +215,9 @@ class PricesTest extends PHPUnit_Framework_TestCase $newlocalobject=new Facture($this->savdb); $newlocalobject->fetch($invoiceid); - $this->assertEquals(2.48,$newlocalobject->total_ht); - $this->assertEquals(0.24,$newlocalobject->total_tva); - $this->assertEquals(2.72,$newlocalobject->total_ttc); + $this->assertEquals(2.48,$newlocalobject->total_ht, "testUpdatePrice test1"); + $this->assertEquals(0.24,$newlocalobject->total_tva, "testUpdatePrice test2"); + $this->assertEquals(2.72,$newlocalobject->total_ttc, "testUpdatePrice test3"); // Two lines of 1.24 give 2.48 HT and 2.73 TTC with global vat rounding mode @@ -231,7 +231,7 @@ class PricesTest extends PHPUnit_Framework_TestCase $newlocalobject=new Facture($this->savdb); $newlocalobject->fetch($invoiceid); - $this->assertEquals(2.48,$newlocalobject->total_ht); + $this->assertEquals(2.48,$newlocalobject->total_ht, "testUpdatePrice test4"); //$this->assertEquals(0.25,$newlocalobject->total_tva); //$this->assertEquals(2.73,$newlocalobject->total_ttc); }