diff --git a/build/rpm/dolibarr_fedora.spec b/build/rpm/dolibarr_fedora.spec index b6d526bf8e1..881b5b1a6a4 100755 --- a/build/rpm/dolibarr_fedora.spec +++ b/build/rpm/dolibarr_fedora.spec @@ -191,6 +191,7 @@ done >>%{name}.lang %_datadir/dolibarr/htdocs/ftp %_datadir/dolibarr/htdocs/holiday %_datadir/dolibarr/htdocs/hrm +%_datadir/dolibarr/htdocs/ifttt %_datadir/dolibarr/htdocs/imports %_datadir/dolibarr/htdocs/includes %_datadir/dolibarr/htdocs/install diff --git a/build/rpm/dolibarr_generic.spec b/build/rpm/dolibarr_generic.spec index 32c6e50018e..74d6bf700bb 100755 --- a/build/rpm/dolibarr_generic.spec +++ b/build/rpm/dolibarr_generic.spec @@ -271,6 +271,7 @@ done >>%{name}.lang %_datadir/dolibarr/htdocs/ftp %_datadir/dolibarr/htdocs/holiday %_datadir/dolibarr/htdocs/hrm +%_datadir/dolibarr/htdocs/ifttt %_datadir/dolibarr/htdocs/imports %_datadir/dolibarr/htdocs/includes %_datadir/dolibarr/htdocs/install diff --git a/build/rpm/dolibarr_mandriva.spec b/build/rpm/dolibarr_mandriva.spec index dbb8e0d1310..181bdb4ded4 100755 --- a/build/rpm/dolibarr_mandriva.spec +++ b/build/rpm/dolibarr_mandriva.spec @@ -188,6 +188,7 @@ done >>%{name}.lang %_datadir/dolibarr/htdocs/ftp %_datadir/dolibarr/htdocs/holiday %_datadir/dolibarr/htdocs/hrm +%_datadir/dolibarr/htdocs/ifttt %_datadir/dolibarr/htdocs/imports %_datadir/dolibarr/htdocs/includes %_datadir/dolibarr/htdocs/install diff --git a/build/rpm/dolibarr_opensuse.spec b/build/rpm/dolibarr_opensuse.spec index aa810a737b9..1410e5097cf 100755 --- a/build/rpm/dolibarr_opensuse.spec +++ b/build/rpm/dolibarr_opensuse.spec @@ -199,6 +199,7 @@ done >>%{name}.lang %_datadir/dolibarr/htdocs/ftp %_datadir/dolibarr/htdocs/holiday %_datadir/dolibarr/htdocs/hrm +%_datadir/dolibarr/htdocs/ifttt %_datadir/dolibarr/htdocs/imports %_datadir/dolibarr/htdocs/includes %_datadir/dolibarr/htdocs/install diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 81a29a0ac04..d007885895c 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -174,14 +174,23 @@ class FormFile $out .= ""; if ($savingdocmask) - { - $out .= ''; - if (! empty($options)) $out .= ''.$options.''; - $out .= ''; - $out .= ' '.$langs->trans("SaveUploadedFileWithMask", preg_replace('/__file__/', $langs->transnoentitiesnoconv("OriginFileName"), $savingdocmask), $langs->transnoentitiesnoconv("OriginFileName")); - $out .= ''; - $out .= ''; - } + { + //add a global variable for disable the auto renaming on upload + if (! empty($conf->global->MAIN_DOC_UPLOAD_NOT_RENAME_BY_DEFAULT)) + { + $rename=''; + } + else { + $rename='checked'; + } + + $out .= ''; + if (! empty($options)) $out .= ''.$options.''; + $out .= ''; + $out .= ' '.$langs->trans("SaveUploadedFileWithMask", preg_replace('/__file__/',$langs->transnoentitiesnoconv("OriginFileName"),$savingdocmask), $langs->transnoentitiesnoconv("OriginFileName")); + $out .= ''; + $out .= ''; + } $out .= ""; @@ -1555,22 +1564,14 @@ class FormFile $id=0; $ref=''; $label=''; // To show ref or specific information according to view to show (defined by $module) - if ($modulepart == 'company') { preg_match('/(\d+)\/[^\/]+$/', $relativefile, $reg); $id=(isset($reg[1])?$reg[1]:''); } - elseif ($modulepart == 'invoice') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref=(isset($reg[1])?$reg[1]:''); } - elseif ($modulepart == 'invoice_supplier') { preg_match('/([^\/]+)\/[^\/]+$/', $relativefile, $reg); $ref=(isset($reg[1])?$reg[1]:''); if (is_numeric($ref)) { $id=$ref; $ref=''; } } // $ref may be also id with old supplier invoices - elseif ($modulepart == 'propal') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref=(isset($reg[1])?$reg[1]:''); } - elseif ($modulepart == 'supplier_proposal') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref=(isset($reg[1])?$reg[1]:''); } - elseif ($modulepart == 'order') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref=(isset($reg[1])?$reg[1]:''); } - elseif ($modulepart == 'order_supplier') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref=(isset($reg[1])?$reg[1]:''); } - elseif ($modulepart == 'contract') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref=(isset($reg[1])?$reg[1]:''); } - elseif ($modulepart == 'product') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref=(isset($reg[1])?$reg[1]:''); } - elseif ($modulepart == 'tax') { preg_match('/(\d+)\/[^\/]+$/', $relativefile, $reg); $id=(isset($reg[1])?$reg[1]:''); } - elseif ($modulepart == 'project') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref=(isset($reg[1])?$reg[1]:'');} - elseif ($modulepart == 'fichinter') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref=(isset($reg[1])?$reg[1]:'');} - elseif ($modulepart == 'user') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $id=(isset($reg[1])?$reg[1]:'');} - elseif ($modulepart == 'expensereport') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref=(isset($reg[1])?$reg[1]:'');} - elseif ($modulepart == 'holiday') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $id=(isset($reg[1])?$reg[1]:'');} - + if ($modulepart == 'company' || $modulepart == 'tax') { preg_match('/(\d+)\/[^\/]+$/', $relativefile, $reg); $id=(isset($reg[1])?$reg[1]:''); } + elseif ($modulepart == 'invoice_supplier') { preg_match('/([^\/]+)\/[^\/]+$/', $relativefile, $reg); $ref=(isset($reg[1])?$reg[1]:''); if (is_numeric($ref)) { $id=$ref; $ref=''; } } // $ref may be also id with old supplier invoices + elseif ($modulepart == 'user' || $modulepart == 'holiday') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $id=(isset($reg[1])?$reg[1]:''); } + elseif (in_array($modulepart, array('invoice', 'propal', 'supplier_proposal', 'order', 'order_supplier', 'contract', 'product', 'project', 'fichinter', 'expensereport'))) + { + preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref=(isset($reg[1])?$reg[1]:''); + } + if (! $id && ! $ref) continue; $found=0; if (! empty($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) diff --git a/htdocs/core/lib/geturl.lib.php b/htdocs/core/lib/geturl.lib.php index 69da66fa99c..9a78e7a3dbf 100644 --- a/htdocs/core/lib/geturl.lib.php +++ b/htdocs/core/lib/geturl.lib.php @@ -78,6 +78,11 @@ function getURLContent($url, $postorget = 'GET', $param = '', $followlocation = curl_setopt($ch, CURLOPT_POST, 1); // POST curl_setopt($ch, CURLOPT_POSTFIELDS, $param); // Setting param x=a&y=z as POST fields } + elseif ($postorget == 'POSTALREADYFORMATED') + { + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); // HTTP request is 'POST' but param string is taken as it is + curl_setopt($ch, CURLOPT_POSTFIELDS, $param); // param = content of post, like a xml string + } elseif ($postorget == 'PUT') { curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // HTTP request is 'PUT' diff --git a/htdocs/core/modules/modIFTTT.class.php b/htdocs/core/modules/modIFTTT.class.php new file mode 100644 index 00000000000..55739978715 --- /dev/null +++ b/htdocs/core/modules/modIFTTT.class.php @@ -0,0 +1,251 @@ + + * + * 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 . + */ + +/** + * \defgroup ifttt Module IFTTT + * \brief Descriptor file for IFTTT module + * \file htdocs/core/modules/modIFTTT.class.php + * \ingroup ifttt + * \brief Description and activation file for module IFTTT + */ +include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php'; + + +/** + * Description and activation class for module IFTTT + */ +class modIFTTT extends DolibarrModules +{ + /** + * Constructor. Define names, constants, directories, boxes, permissions + * + * @param DoliDB $db Database handler + */ + function __construct($db) + { + global $langs,$conf; + + $this->db = $db; + + // Id for module (must be unique). + // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id). + $this->numero = 2620; + // Key text used to identify module (for permissions, menus, etc...) + $this->rights_class = 'ifttt'; + + // Family can be 'crm','financial','hr','projects','products','ecm','technic','other' + // It is used to group modules in module setup page + $this->family = "interface"; + // 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)); + // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module) + $this->description = "IFTTT interface"; + // Possible values for version are: 'development', 'experimental', 'dolibarr' or 'dolibarr_deprecated' or version + $this->version = 'development'; + // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase) + $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); + // Can be enabled / disabled only in the main company with superadmin account + $this->core_enabled = 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'; + + $this->module_parts = array(); + + // Data directories to create when module is enabled. + // Example: this->dirs = array("/api/temp"); + $this->dirs = array(); + + // Config pages. Put here list of php page, stored into api/admin directory, to use to setup module. + $this->config_page_url = array("index.php@ifttt"); + + // Dependencies + $this->hidden = false; // A condition to hide module + $this->depends = array(); // List of modules id that must be enabled if this module is enabled + $this->requiredby = array(); // List of modules id to disable if this one is disabled + $this->conflictwith = array(); // List of modules id this module is in conflict with + $this->phpmin = array(5,4); // Minimum version of PHP required by module + $this->langfiles = array("other"); + + // Constants + // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive) + // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1), + // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1) + // ); + $this->const = array(); + + // Array to add new pages in new tabs + // Example: $this->tabs = array('objecttype:+tabname1:Title1:mylangfile@api:$user->rights->ifttt->read:/api/mynewtab1.php?id=__ID__', // To add a new tab identified by code tabname1 + // 'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@api:$user->rights->othermodule->read:/api/mynewtab2.php?id=__ID__', // To add another new tab identified by code tabname2. Label will be result of calling all substitution functions on 'Title2' key. + // 'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname + // where objecttype can be + // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member) + // 'contact' to add a tab in contact view + // 'contract' to add a tab in contract view + // 'group' to add a tab in group view + // 'intervention' to add a tab in intervention view + // 'invoice' to add a tab in customer invoice view + // 'invoice_supplier' to add a tab in supplier invoice view + // 'member' to add a tab in fundation member view + // 'opensurveypoll' to add a tab in opensurvey poll view + // 'order' to add a tab in customer order view + // 'order_supplier' to add a tab in supplier order view + // 'payment' to add a tab in payment view + // 'payment_supplier' to add a tab in supplier payment view + // 'product' to add a tab in product view + // 'propal' to add a tab in propal view + // 'project' to add a tab in project view + // 'stock' to add a tab in stock view + // 'thirdparty' to add a tab in third party view + // 'user' to add a tab in user view + $this->tabs = array(); + + // Dictionaries + if (! isset($conf->ifttt->enabled)) + { + $conf->ifttt=new stdClass(); + $conf->ifttt->enabled=0; + } + $this->dictionaries=array(); + + // Boxes + // Add here list of php file(s) stored in core/boxes that contains class to show a box. + $this->boxes = array(); // List of boxes + // Example: + //$this->boxes=array(array(0=>array('file'=>'myboxa.php','note'=>'','enabledbydefaulton'=>'Home'),1=>array('file'=>'myboxb.php','note'=>''),2=>array('file'=>'myboxc.php','note'=>''));); + + // Permissions + $this->rights = array(); // Permission array used by this module + $r=0; + + // Add here list of permission defined by an id, a label, a boolean and two constant strings. + // Example: + // $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used) + // $this->rights[$r][1] = 'Permision label'; // Permission label + // $this->rights[$r][3] = 0; // Permission by default for new user (0/1) + // $this->rights[$r][4] = 'level1'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) + // $this->rights[$r][5] = 'level2'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) + // $r++; + + + // Main menu entries + $this->menu = array(); // List of menus to add + $r=0; + + // Add here entries to declare new menus + // + // Example to declare a new Top Menu entry and its Left menu entry: + // $this->menu[$r]=array( 'fk_menu'=>0, // Put 0 if this is a top menu + // 'type'=>'top', // This is a Top menu entry + // 'titre'=>'Api top menu', + // 'mainmenu'=>'api', + // 'leftmenu'=>'api', + // 'url'=>'/api/pagetop.php', + // 'langs'=>'mylangfile@api', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. + // 'position'=>100, + // 'enabled'=>'$conf->ifttt->enabled', // Define condition to show or hide menu entry. Use '$conf->ifttt->enabled' if entry must be visible if module is enabled. + // 'perms'=>'1', // Use 'perms'=>'$user->rights->ifttt->level1->level2' if you want your menu with a permission rules + // 'target'=>'', + // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both + // $r++; + // + // Example to declare a Left Menu entry into an existing Top menu entry: + // $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=xxx', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode + // 'type'=>'left', // This is a Left menu entry + // 'titre'=>'Api left menu', + // 'mainmenu'=>'xxx', + // 'leftmenu'=>'api', + // 'url'=>'/api/pagelevel2.php', + // 'langs'=>'mylangfile@api', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. + // 'position'=>100, + // 'enabled'=>'$conf->ifttt->enabled', // Define condition to show or hide menu entry. Use '$conf->ifttt->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected. + // 'perms'=>'1', // Use 'perms'=>'$user->rights->ifttt->level1->level2' if you want your menu with a permission rules + // 'target'=>'', + // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both + // $r++; + + + // Exports + $r=1; + + // Example: + // $this->export_code[$r]=$this->rights_class.'_'.$r; + // $this->export_label[$r]='CustomersInvoicesAndInvoiceLines'; // Translation key (used only if key ExportDataset_xxx_z not found) + // $this->export_enabled[$r]='1'; // Condition to show export in list (ie: '$user->id==3'). Set to 1 to always show when module is enabled. + // $this->export_permission[$r]=array(array("facture","facture","export")); + // $this->export_fields_array[$r]=array( + // 's.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','s.fk_pays'=>'Country','s.phone'=>'Phone', + // 's.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode', + // 's.code_compta_fournisseur'=>'SupplierAccountancyCode','f.rowid'=>"InvoiceId",'f.ref'=>"InvoiceRef",'f.datec'=>"InvoiceDateCreation", + // 'f.datef'=>"DateInvoice",'f.total'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus', + // 'f.note'=>"InvoiceNote",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.price'=>"LineUnitPrice",'fd.tva_tx'=>"LineVATRate", + // 'fd.qty'=>"LineQty",'fd.total_ht'=>"LineTotalHT",'fd.total_tva'=>"LineTotalTVA",'fd.total_ttc'=>"LineTotalTTC",'fd.date_start'=>"DateStart", + // 'fd.date_end'=>"DateEnd",'fd.fk_product'=>'ProductId','p.ref'=>'ProductRef' + //); + // $this->export_entities_array[$r]=array( + // 's.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','s.fk_pays'=>'company','s.phone'=>'company', + // 's.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company', + // 'f.rowid'=>"invoice",'f.ref'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice", + // 'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line", + // 'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line", + // 'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line",'fd.fk_product'=>'product','p.ref'=>'product' + //); + // $this->export_sql_start[$r]='SELECT DISTINCT '; + // $this->export_sql_end[$r] =' FROM ('.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'facturedet as fd, '.MAIN_DB_PREFIX.'societe as s)'; + // $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)'; + // $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture'; + // $this->export_sql_order[$r] .=' ORDER BY s.nom'; + // $r++; + } + + /** + * Function called when module is enabled. + * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. + * It also creates data directories + * + * @param string $options Options when enabling module ('', 'noboxes') + * @return int 1 if OK, 0 if KO + */ + function init($options = '') + { + $sql = array(); + + $result=$this->_load_tables('/ifttt/sql/'); + + return $this->_init($sql, $options); + } + + /** + * Function called when module is disabled. + * Remove from database constants, boxes and permissions from Dolibarr database. + * Data directories are not deleted. + * + * @param string $options Options when enabling module ('', 'noboxes') + * @return int 1 if OK, 0 if KO + */ + function remove($options = '') + { + // Remove old constants with entity fields different of 0 + $sql = array( + "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = ".$this->db->encrypt('MAIN_MODULE_IFTTT', 1), + "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = ".$this->db->encrypt('IFTTT_PRODUCTION_MODE', 1) + ); + + return $this->_remove($sql, $options); + } +} diff --git a/htdocs/core/triggers/interface_50_modIFTTT_IFTTT.class.php b/htdocs/core/triggers/interface_50_modIFTTT_IFTTT.class.php new file mode 100644 index 00000000000..c7ce8f121fc --- /dev/null +++ b/htdocs/core/triggers/interface_50_modIFTTT_IFTTT.class.php @@ -0,0 +1,147 @@ + + * 2016 Christophe Battarel + * + * 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/core/triggers/interface_50_modIFTTT_IFTTT.class.php + * \ingroup core + * \brief File of trigger for IFTTT module + */ +require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; + + +/** + * Class of triggers for IFTTT module + */ +class InterfaceIFTTT extends DolibarrTriggers +{ + /** + * @var DoliDB Database handler. + */ + public $db; + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; + + $this->name = preg_replace('/^Interface/i', '', get_class($this)); + $this->family = "ifttt"; + $this->description = "Triggers of the module IFTTT"; + $this->version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' or version + $this->picto = 'ifttt'; + } + + /** + * Return name of trigger file + * + * @return string Name of trigger file + */ + public function getName() + { + return $this->name; + } + + /** + * Return description of trigger file + * + * @return string Description of trigger file + */ + public function getDesc() + { + return $this->description; + } + + /** + * Return version of trigger file + * + * @return string Version of trigger file + */ + public function getVersion() + { + global $langs; + $langs->load("admin"); + + if ($this->version == 'development') { + return $langs->trans("Development"); + } elseif ($this->version == 'experimental') { + return $langs->trans("Experimental"); + } elseif ($this->version == 'dolibarr') { + return DOL_VERSION; + } elseif ($this->version) { + return $this->version; + } else { + return $langs->trans("Unknown"); + } + } + + /** + * Function called when a Dolibarrr business event is done. + * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers + * + * @param string $action Event action code + * @param Object $object Object + * @param User $user Object user + * @param Translate $langs Object langs + * @param conf $conf Object conf + * @return int <0 if KO, 0 if no triggered ran, >0 if OK + */ + public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) + { + $ok = 0; + + if (empty($conf->ifttt->enabled)) return 0; // Module not active, we do nothing + + switch ($action) { + case 'THIRDPARTY_CREATED': + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); + + include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php'; + + // See https://platform.ifttt.com/docs/api_reference#realtime-api + + $arrayofdata=array(); + $arrayofdata['user_id']=$conf->global->IFTTT_USER_ID; + $arrayofdata['trigger_identity']=$conf->global->IFTTT_TRIGGER_IDENTITY; + $arrayofdata['name']='testabcdef'; + $arrayofdata['email']='testemailabcdef'; + + $url = 'https://realtime.ifttt.com/v1/notifications'; + + $addheaders=array( + 'IFTTT-Service-Key'=>'123', + 'Accept'=>'application/json', + 'Accept-Charset'=>'utf-8', + 'Accept-Encoding'=>'gzip, deflate', + 'Content-Type'=>'application/json', + 'X-Request-ID'=>getRandomPassword(true, null) + ); + + $result = getURLContent($url, 'POSTALREADYFORMATED', '', 1, $addheaders); + + $ok = 1; + break; + } + + return $ok; + } +} diff --git a/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php b/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php index f8f5595887d..c8a31a70e40 100644 --- a/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php +++ b/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php @@ -109,6 +109,8 @@ class InterfaceTicketEmail extends DolibarrTriggers { $ok = 0; + if (empty($conf->ticket->enabled)) return 0; // Module not active, we do nothing + switch ($action) { case 'TICKET_ASSIGNED': dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); diff --git a/htdocs/cron/class/cronjob.class.php b/htdocs/cron/class/cronjob.class.php index 99020e287f4..1f22e7b910c 100644 --- a/htdocs/cron/class/cronjob.class.php +++ b/htdocs/cron/class/cronjob.class.php @@ -937,7 +937,9 @@ class Cronjob extends CommonObject public function run_jobs($userlogin) { // phpcs:enable - global $langs, $conf; + global $langs, $conf, $hookmanager; + + $hookmanager->initHooks(array('cron')); $now=dol_now(); $error = 0; diff --git a/htdocs/hrm/class/establishment.class.php b/htdocs/hrm/class/establishment.class.php index 2f21d83436b..530287084ca 100644 --- a/htdocs/hrm/class/establishment.class.php +++ b/htdocs/hrm/class/establishment.class.php @@ -396,7 +396,7 @@ class Establishment extends CommonObject * Get on record Establishment * * @param int $id Id of record - * @return obj + * @return Object */ function getEstablishment($id) { @@ -457,7 +457,7 @@ class Establishment extends CommonObject */ function getNomUrlParent($id = 0, $withpicto = 0) { - global $langs; + global $langs, $conf; $result=''; diff --git a/htdocs/ifttt/README.md b/htdocs/ifttt/README.md new file mode 100644 index 00000000000..581853f80c6 --- /dev/null +++ b/htdocs/ifttt/README.md @@ -0,0 +1,7 @@ +API REST +======== + +## Integrate your ERP with any other applications using IFTTT + +This module provides the triggers and services to make Dolibarr compatible with IFTTT Services. + diff --git a/htdocs/ifttt/admin/index.php b/htdocs/ifttt/admin/index.php new file mode 100644 index 00000000000..d6eb777109b --- /dev/null +++ b/htdocs/ifttt/admin/index.php @@ -0,0 +1,131 @@ + + * Copyright (C) 2005-2016 Laurent Destailleur + * Copyright (C) 2011 Juanjo Menent + * Copyright (C) 2012-2018 Regis Houssin + * Copyright (C) 2015 Jean-François Ferry + * + * 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/ifttt/admin/index.php + * \ingroup api + * \brief Page to setup IFTTT module + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + +// Load translation files required by the page +$langs->load("admin"); + +if (! $user->admin) + accessforbidden(); + +$action=GETPOST('action', 'aZ09'); + + +if ($action == 'setproductionmode') +{ + $status = GETPOST('status', 'alpha'); + + if (dolibarr_set_const($db, 'IFTTT_PRODUCTION_MODE', $status, 'chaine', 0, '', 0) > 0) + { + header("Location: ".$_SERVER["PHP_SELF"]); + exit; + } + else + { + dol_print_error($db); + } +} + + +/* + * View + */ + +llxHeader(); + +$linkback=''.$langs->trans("BackToModuleList").''; +print load_fiche_titre($langs->trans("IFTTTSetup"), $linkback, 'title_setup'); + +print $langs->trans("IFTTTDesc")."
\n"; +print "
\n"; + +//print '
'; +print ''; +print ''; + +print ''; +print ""; +print '"; +print ""; +print ""; + +print ''; +print ''; +$production_mode=(empty($conf->global->IFTTT_PRODUCTION_MODE)?false:true); +if ($production_mode) +{ + print ''; +} +else +{ + print ''; +} +print ''; +print ''; + +print '
".$langs->trans("Parameter")."'.$langs->trans("Value")." 
'.$langs->trans("ProductionMode").''; + print img_picto($langs->trans("Activated"), 'switch_on'); + print ''; + print img_picto($langs->trans("Disabled"), 'switch_off'); + print ' 
'; +print '

'; + +/* + +// Define $urlwithroot +$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); +$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file +//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current + +// Show message +$message=''; +$url=$urlwithroot.'/api/index.php/login?login=auserlogin&password=thepassword[&reset=1]'; +$message.=$langs->trans("UrlToGetKeyToUseAPIs").':
'; +$message.=img_picto('', 'object_globe.png').' '.$url; +print $message; +print '
'; +print '
'; + +// Explorer +print ''.$langs->trans("ApiExporerIs").':
'; +if (dol_is_dir(DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/explorer')) +{ + $url=DOL_MAIN_URL_ROOT.'/api/index.php/explorer'; + print img_picto('', 'object_globe.png').' '.$url."
\n"; +} +else +{ + print $langs->trans("NotAvailableWithThisDistribution"); +} + +*/ + +llxFooter(); +$db->close(); diff --git a/htdocs/product/stock/movement_list.php b/htdocs/product/stock/movement_list.php index d37271f6480..6c3f5b6b7ce 100644 --- a/htdocs/product/stock/movement_list.php +++ b/htdocs/product/stock/movement_list.php @@ -404,28 +404,6 @@ if ($action == "transfert_stock" && ! $cancel) } -/* - * Build document - */ -/* The builddoc action for object of a movement must be on the movement card -// Actions to build doc -$upload_dir = $conf->stock->dir_output; -$permissioncreate = $user->rights->stock->creer; -include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; -*/ - -if (empty($reshook) && $action != 'remove_file') -{ - $objectclass='MouvementStock'; - $objectlabel='Movements'; - $permtoread = $user->rights->stock->lire; - $permtodelete = $user->rights->stock->supprimer; - $uploaddir = $conf->stock->dir_output; - include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; -} - - - /* * View */ @@ -1070,7 +1048,7 @@ if ($resql) { // Inventory code print ''.'
'; - print ''; // ancre - - // Documents - $objectref = dol_sanitizeFileName($object->ref); - // Add inventorycode & type_mouvement to filename of the pdf - if(!empty($search_inventorycode)) $objectref.="_".$id."_".$search_inventorycode; - if($search_type_mouvement) $objectref.="_".$search_type_mouvement; - $relativepath = $comref . '/' . $objectref . '.pdf'; - $filedir = $conf->stock->dir_output . '/movement/' . $objectref; - - $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id."&search_inventorycode=".$search_inventorycode."&search_type_mouvement=$search_type_mouvement"; - $genallowed=$usercanread; - $delallowed=$usercancreate; - - $genallowed=$user->rights->stock->mouvement->lire; - $delallowed=$user->rights->stock->mouvement->creer; - - print $formfile->showdocuments($modulepart,$objectref,$filedir,$urlsource,$genallowed,$delallowed,'',0,0,0,28,0,'',0,'',$object->default_lang, '', $object); - $somethingshown=$formfile->numoffiles; - - print '
'; - - $MAXEVENT = 10; - - $morehtmlright = ''; - $morehtmlright.= $langs->trans("SeeAll"); - $morehtmlright.= ''; - - // List of actions on element - include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; - $formactions = new FormActions($db); - $somethingshown = $formactions->showactions($object, 'stock', 0, 1, '', $MAXEVENT, '', $morehtmlright); // Show all action for product - - print '
'; -} -*/ - // End of page llxFooter(); $db->close();