diff --git a/htdocs/core/modules/modPrintIPP.class.php b/htdocs/core/modules/modPrintIPP.class.php new file mode 100644 index 00000000000..53cadf53699 --- /dev/null +++ b/htdocs/core/modules/modPrintIPP.class.php @@ -0,0 +1,145 @@ +. + */ + +/** \defgroup printipp Module printipp + * \brief Module pour imprimer via CUPS + */ + +/** + * \file htdocs/core/modules/modPrintIPP.class.php + * \ingroup printipp + * \brief Fichier de description et activation du module OSCommerce2 + */ +include_once(DOL_DOCUMENT_ROOT ."/core/modules/DolibarrModules.class.php"); + + + +/** + * \class modPrintIPP + * \brief Classe de description et activation du module PrintIPP + */ +class modPrintIPP extends DolibarrModules +{ + + /** + * \brief Constructeur. Definit les noms, constantes et boites + * \param DB handler d'acces base + */ + function __construct($db) + { + $this->db = $db ; + $this->numero = 54000; + // Family can be 'crm','financial','hr','projects','products','ecm','technic','other' + // It is used to group modules in module setup page + $this->family = "other"; + // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) + $this->name = preg_replace('/^mod/i','',get_class($this)); + $this->description = "Print via Cups IPP Printer."; + $this->version = 'experimental'; // 'development' or 'experimental' or 'dolibarr' or version + $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); + // Where to store the module in setup page (0=common,1=interface,2=others,3=very specific) + $this->special = 1; + // Name of image file used for this module. + // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue' + // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module' + $this->picto = 'technic'; + + // Data directories to create when module is enabled. + $this->dirs = array(); + + // Config pages + $this->config_page_url = array("printipp.php@printipp"); + + // Dependances + $this->depends = array(); + $this->requiredby = array(); + $this->phpmin = array(5,1); // Minimum version of PHP required by module + $this->need_dolibarr_version = array(3,2); // Minimum version of Dolibarr required by module + $this->conflictwith = array(); + $this->langfiles = array("printipp"); + + // Constantes + $this->const = array(); + + // Boxes + $this->boxes = array(); + + // Permissions + $this->rights = array(); + $this->rights_class = 'printipp'; + + $r=0; + // $this->rights[$r][0] Id permission (unique tous modules confondus) + // $this->rights[$r][1] Libelle par defaut si traduction de cle "PermissionXXX" non trouvee (XXX = Id permission) + // $this->rights[$r][2] Non utilise + // $this->rights[$r][3] 1=Permis par defaut, 0=Non permis par defaut + // $this->rights[$r][4] Niveau 1 pour nommer permission dans code + // $this->rights[$r][5] Niveau 2 pour nommer permission dans code + + $r++; + $this->rights[$r][0] = 54001; + $this->rights[$r][1] = 'Printer'; + $this->rights[$r][2] = 'r'; + $this->rights[$r][3] = 1; + $this->rights[$r][4] = 'use'; + + // Main menu entries + $this->menus = array(); // List of menus to add + $r=0; + + // This is to declare the Top Menu entry: + $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=home', // Put 0 if this is a top menu + 'type'=>'left', // This is a Top menu entry + 'titre'=>'Printer', + 'mainmenu'=>'printer', + 'url'=>'/printipp/index.php', + 'langs'=>'printipp', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. + 'position'=>100, + 'enabled'=>'$conf->printipp->enabled', + 'perms'=>'$user->rights->printipp->use', // Use 'perms'=>'1' if you want your menu with no permission rules + 'target'=>'', + 'user'=>0); // 0=Menu for internal users, 1=external users, 2=both + + $r++; + + + } + + /** + * \brief Fonction appelee lors de l'activation du module. Insere en base les constantes, boites, permissions du module. + * Definit egalement les repertoires de donnees a creer pour ce module. + */ + function init() + { + $sql = array("CREATE TABLE IF NOT EXISTS llx_printer_ipp (rowid int(11) NOT NULL AUTO_INCREMENT,printer_name text NOT NULL, printer_location text NOT NULL,printer_uri varchar(256) NOT NULL,copy int(11) NOT NULL DEFAULT '1',module varchar(16) NOT NULL,login varchar(32) NOT NULL,PRIMARY KEY (rowid)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"); + + return $this->_init($sql); + } + + /** + * \brief Fonction appelee lors de la desactivation d'un module. + * Supprime de la base les constantes, boites et permissions du module. + */ + function remove() + { + $sql = array(); + + return $this->_remove($sql); + } + +} +?> diff --git a/htdocs/printipp/admin/printipp.php b/htdocs/printipp/admin/printipp.php new file mode 100644 index 00000000000..a96e10d3996 --- /dev/null +++ b/htdocs/printipp/admin/printipp.php @@ -0,0 +1,159 @@ +. + */ + +/** + * \file htdocs/printipp/admin/printipp.php + * \ingroup core + * \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'); + +if (!$mode) $mode='config'; + +/* + * Action + */ +if ($action == 'setvalue' && $user->admin) +{ + $db->begin(); + $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); + } +} + + +/* + * 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(); + +dol_fiche_head($head, $mode, $langs->trans("ModuleSetup")); + +print $langs->trans("PrintIPPDesc")."
\n"; + + + print '
'; + +if ($mode=='config'&& $user->admin) +{ + print '
'; + print ''; + print ''; + + + print ''; + + $var=true; + print ''; + print ''; + print ''; + print "\n"; + + $var=!$var; + print ''; + + $var=!$var; + print ''; + + $var=!$var; + print ''; + + $var=!$var; + print ''; + + //$var=true; + //print ''; + //print ''; + //print ''; + //print "\n"; + + print ''; + + print '
'.$langs->trans("AccountParameter").''.$langs->trans("Value").'
'; + 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").'

'; + + print '
'; +} + +if ($mode=='test'&& $user->admin) +{ + 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_r($printer->getlist_available_printers(),true); + print "\n"; + print '
'.$langs->trans("TestConnect").'
'; +} + +dol_fiche_end(); + +llxFooter(); +$db->close(); +?> \ No newline at end of file diff --git a/htdocs/printipp/index.php b/htdocs/printipp/index.php new file mode 100644 index 00000000000..5a9e60a6280 --- /dev/null +++ b/htdocs/printipp/index.php @@ -0,0 +1,36 @@ +. + */ + +/** +\file htdocs/printipp/index.php +\ingroup printipp +\brief Printipp +*/ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/dolprintipp.class.php'; + +llxHeader("",$langs->trans("Printer")); + +print_fiche_titre($langs->trans("Printer")); + +$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/printipp/lib/printipp.lib.php b/htdocs/printipp/lib/printipp.lib.php new file mode 100644 index 00000000000..ec249765fbc --- /dev/null +++ b/htdocs/printipp/lib/printipp.lib.php @@ -0,0 +1,61 @@ +. + */ + +/** + * \file htdocs/printipp/lib/printipp.lib.php + * \ingroup printipp + * \brief Library for printipp functions + */ + + + +/** + * Define head array for tabs of printipp tools setup pages + * + * @return Array of head + */ +function printippadmin_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("Config"); + $head[$h][2] = 'config'; + $h++; + + $head[$h][0] = DOL_URL_ROOT."/printipp/admin/printipp.php?mode=test"; + $head[$h][1] = $langs->trans("Test"); + $head[$h][2] = 'test'; + $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,'printipp','remove'); + + return $head; +} + +?> \ No newline at end of file