From 13d6664ab499ac66f036388fd8f6a7924e9876ca Mon Sep 17 00:00:00 2001 From: fappels Date: Sun, 9 Jul 2017 12:47:51 +0200 Subject: [PATCH 01/22] Fix delete product from product card --- htdocs/product/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 3266d02f2f4..0a6c9052b91 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -561,7 +561,7 @@ if (empty($reshook)) { if (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->supprimer) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->supprimer)) { - $result = $object->delete(DolibarrApiAccess::$user); + $result = $object->delete($user); } if ($result > 0) From 10cb7b2524c1e08ae6c9d16218dac3277c8a0f68 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 9 Jul 2017 20:31:27 +0200 Subject: [PATCH 02/22] Fix remove warnings --- htdocs/admin/notification.php | 8 +++--- htdocs/bookmarks/bookmarks.lib.php | 8 +++--- htdocs/comm/action/index.php | 18 ++++++++----- htdocs/comm/action/listactions.php | 11 +++++--- htdocs/core/actions_setmoduleoptions.inc.php | 17 +++++++----- htdocs/install/step1.php | 11 +++++--- htdocs/main.inc.php | 10 +++++--- htdocs/projet/activity/perday.php | 27 +++++++++++--------- htdocs/theme/eldy/ckeditor/config.js | 5 +++- htdocs/theme/md/ckeditor/config.js | 5 +++- 10 files changed, 74 insertions(+), 46 deletions(-) diff --git a/htdocs/admin/notification.php b/htdocs/admin/notification.php index 73fb3d91587..04427f636cd 100644 --- a/htdocs/admin/notification.php +++ b/htdocs/admin/notification.php @@ -55,7 +55,7 @@ if ($action == 'setvalue' && $user->admin) $result=dolibarr_set_const($db, "NOTIFICATION_EMAIL_FROM", $_POST["email_from"], 'chaine', 0, '', $conf->entity); if ($result < 0) $error++; - if (! $error) + if (! $error && is_array($_POST)) { //var_dump($_POST); foreach($_POST as $key => $val) @@ -172,7 +172,7 @@ $var=true; $i=0; foreach($listofnotifiedevents as $notifiedevent) { - + $label=$langs->trans("Notify_".$notifiedevent['code']); //!=$langs->trans("Notify_".$notifiedevent['code'])?$langs->trans("Notify_".$notifiedevent['code']):$notifiedevent['label']; if ($notifiedevent['elementtype'] == 'order_supplier') $elementLabel = $langs->trans('SupplierOrder'); @@ -183,7 +183,7 @@ foreach($listofnotifiedevents as $notifiedevent) if ($i) print ', '; print $label; - + $i++; } print ''; @@ -213,7 +213,7 @@ $listofnotifiedevents=$notificationtrigger->getListOfManagedEvents(); $var=true; foreach($listofnotifiedevents as $notifiedevent) { - + $label=$langs->trans("Notify_".$notifiedevent['code']); //!=$langs->trans("Notify_".$notifiedevent['code'])?$langs->trans("Notify_".$notifiedevent['code']):$notifiedevent['label']; if ($notifiedevent['elementtype'] == 'order_supplier') $elementLabel = $langs->trans('SupplierOrder'); diff --git a/htdocs/bookmarks/bookmarks.lib.php b/htdocs/bookmarks/bookmarks.lib.php index 8f8295f0e53..eca126697cc 100644 --- a/htdocs/bookmarks/bookmarks.lib.php +++ b/htdocs/bookmarks/bookmarks.lib.php @@ -53,11 +53,13 @@ function printBookmarksList($aDb, $aLangs) // No urlencode, all param $url will be urlencoded later if ($sortfield) $tmpurl.=($tmpurl?'&':'').'sortfield='.$sortfield; if ($sortorder) $tmpurl.=($tmpurl?'&':'').'sortorder='.$sortorder; - foreach($_POST as $key => $val) + if (is_array($_POST)) { - if (preg_match('/^search_/', $key) && $val != '') $tmpurl.=($tmpurl?'&':'').$key.'='.$val; + foreach($_POST as $key => $val) + { + if (preg_match('/^search_/', $key) && $val != '') $tmpurl.=($tmpurl?'&':'').$key.'='.$val; + } } - $url.=($tmpurl?'?'.$tmpurl:''); } diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index 76a53924ad5..9e293e09799 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -129,10 +129,13 @@ $hookmanager->initHooks(array('agenda')); if (GETPOST("viewlist") || $action == 'show_list') { $param=''; - foreach($_POST as $key => $val) + if (is_array($_POST)) { - if ($key=='token') continue; - $param.='&'.$key.'='.urlencode($val); + foreach($_POST as $key => $val) + { + if ($key=='token') continue; + $param.='&'.$key.'='.urlencode($val); + } } //print $param; header("Location: ".DOL_URL_ROOT.'/comm/action/listactions.php?'.$param); @@ -142,10 +145,13 @@ if (GETPOST("viewlist") || $action == 'show_list') if (GETPOST("viewperuser") || $action == 'show_peruser') { $param=''; - foreach($_POST as $key => $val) + if (is_array($_POST)) { - if ($key=='token') continue; - $param.='&'.$key.'='.urlencode($val); + foreach($_POST as $key => $val) + { + if ($key=='token') continue; + $param.='&'.$key.'='.urlencode($val); + } } //print $param; header("Location: ".DOL_URL_ROOT.'/comm/action/peruser.php?'.$param); diff --git a/htdocs/comm/action/listactions.php b/htdocs/comm/action/listactions.php index 9cb14454cd5..9e0d1530e85 100644 --- a/htdocs/comm/action/listactions.php +++ b/htdocs/comm/action/listactions.php @@ -120,10 +120,13 @@ $hookmanager->initHooks(array('agendalist')); if (GETPOST("viewcal") || GETPOST("viewweek") || GETPOST("viewday")) { $param=''; - foreach($_POST as $key => $val) - { - $param.='&'.$key.'='.urlencode($val); - } + if (is_array($_POST)) + { + foreach($_POST as $key => $val) + { + $param.='&'.$key.'='.urlencode($val); + } + } //print $param; header("Location: ".DOL_URL_ROOT.'/comm/action/index.php?'.$param); exit; diff --git a/htdocs/core/actions_setmoduleoptions.inc.php b/htdocs/core/actions_setmoduleoptions.inc.php index 03b33b19eb1..b8ae96cb920 100644 --- a/htdocs/core/actions_setmoduleoptions.inc.php +++ b/htdocs/core/actions_setmoduleoptions.inc.php @@ -32,16 +32,19 @@ if ($action == 'setModuleOptions') $db->begin(); // Process common param fields - foreach($_POST as $key => $val) + if (is_array($_POST)) { - if (preg_match('/^param(\d*)$/', $key, $reg)) // Works for POST['param'], POST['param1'], POST['param2'], ... + foreach($_POST as $key => $val) { - $param=GETPOST("param".$reg[1],'alpha'); - $value=GETPOST("value".$reg[1],'alpha'); - if ($param) + if (preg_match('/^param(\d*)$/', $key, $reg)) // Works for POST['param'], POST['param1'], POST['param2'], ... { - $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); - if (! $res > 0) $error++; + $param=GETPOST("param".$reg[1],'alpha'); + $value=GETPOST("value".$reg[1],'alpha'); + if ($param) + { + $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); + if (! $res > 0) $error++; + } } } } diff --git a/htdocs/install/step1.php b/htdocs/install/step1.php index a0fdc22a015..a8d17388d41 100644 --- a/htdocs/install/step1.php +++ b/htdocs/install/step1.php @@ -345,11 +345,14 @@ if (! $error && $db->connected) if (! $error && $db->connected && $action == "set") { umask(0); - foreach($_POST as $key => $value) + if (is_array($_POST)) { - if (! preg_match('/^db_pass/i', $key)) { - dolibarr_install_syslog("step1: choice for " . $key . " = " . $value); - } + foreach($_POST as $key => $value) + { + if (! preg_match('/^db_pass/i', $key)) { + dolibarr_install_syslog("step1: choice for " . $key . " = " . $value); + } + } } // Show title of step diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index b5f88def445..1edc67d582f 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -1498,10 +1498,12 @@ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $a { $qs=dol_escape_htmltag($_SERVER["QUERY_STRING"]); - foreach($_POST as $key=>$value) { - if ($key!=='action' && !is_array($value)) $qs.='&'.$key.'='.urlencode($value); - } - + if (is_array($_POST)) + { + foreach($_POST as $key=>$value) { + if ($key!=='action' && !is_array($value)) $qs.='&'.$key.'='.urlencode($value); + } + } $qs.=(($qs && $morequerystring)?'&':'').$morequerystring; $text =''; //$text.= img_picto(":".$langs->trans("PrintContentArea"), 'printer_top.png', 'class="printer"'); diff --git a/htdocs/projet/activity/perday.php b/htdocs/projet/activity/perday.php index 9cda69560d5..908767afe32 100644 --- a/htdocs/projet/activity/perday.php +++ b/htdocs/projet/activity/perday.php @@ -200,22 +200,25 @@ if ($action == 'addtime' && $user->rights->projet->lire) { $timespent_duration=array(); - foreach($_POST as $key => $time) + if (is_array($_POST)) { - if (intval($time) > 0) + foreach($_POST as $key => $time) { - // Hours or minutes of duration - if (preg_match("/([0-9]+)duration(hour|min)/",$key,$matches)) + if (intval($time) > 0) { - $id = $matches[1]; - if ($id > 0) - { - // We store HOURS in seconds - if($matches[2]=='hour') $timespent_duration[$id] += $time*60*60; + // Hours or minutes of duration + if (preg_match("/([0-9]+)duration(hour|min)/",$key,$matches)) + { + $id = $matches[1]; + if ($id > 0) + { + // We store HOURS in seconds + if($matches[2]=='hour') $timespent_duration[$id] += $time*60*60; - // We store MINUTES in seconds - if($matches[2]=='min') $timespent_duration[$id] += $time*60; - } + // We store MINUTES in seconds + if($matches[2]=='min') $timespent_duration[$id] += $time*60; + } + } } } } diff --git a/htdocs/theme/eldy/ckeditor/config.js b/htdocs/theme/eldy/ckeditor/config.js index eabd0c58bd3..e4a86a37293 100644 --- a/htdocs/theme/eldy/ckeditor/config.js +++ b/htdocs/theme/eldy/ckeditor/config.js @@ -25,7 +25,10 @@ CKEDITOR.editorConfig = function( config ) config.dialog_backgroundCoverColor = 'rgb(255, 254, 253)'; //config.contentsCss = '/css/mysitestyles.css'; config.image_previewText=' '; // Must no be empty - + //config.autoParagraph = false; + //config.removeFormatTags = 'b,big,code,del,dfn,em,font,i,ins,kbd'; // See also rules on this.dataProcessor.writer.setRules + //config.forcePasteAsPlainText = true; + config.toolbar_Full = [ ['Templates','NewPage'], diff --git a/htdocs/theme/md/ckeditor/config.js b/htdocs/theme/md/ckeditor/config.js index 6f1bbe7fb30..a6508e62a88 100644 --- a/htdocs/theme/md/ckeditor/config.js +++ b/htdocs/theme/md/ckeditor/config.js @@ -25,7 +25,10 @@ CKEDITOR.editorConfig = function( config ) config.dialog_backgroundCoverColor = 'rgb(255, 254, 253)'; //config.contentsCss = '/css/mysitestyles.css'; config.image_previewText=' '; // Must no be empty - + //config.autoParagraph = false; + //config.removeFormatTags = 'b,big,code,del,dfn,em,font,i,ins,kbd'; // See also rules on this.dataProcessor.writer.setRules + //config.forcePasteAsPlainText = true; + config.toolbar_Full = [ ['Templates','NewPage'], From 3c576dcf21e5bfeaa610a8bdb06457e33a0a214b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 9 Jul 2017 20:57:45 +0200 Subject: [PATCH 03/22] Fix bad name of tables --- htdocs/admin/websites.php | 28 +++++++++---------- .../install/mysql/migration/5.0.0-6.0.0.sql | 25 +++++++++++++++++ .../mysql/tables/llx_website_pages.key.sql | 4 +-- .../mysql/tables/llx_website_pages.sql | 2 +- htdocs/websites/index.php | 3 +- 5 files changed, 44 insertions(+), 18 deletions(-) diff --git a/htdocs/admin/websites.php b/htdocs/admin/websites.php index 0336a2533c0..3b894536d04 100644 --- a/htdocs/admin/websites.php +++ b/htdocs/admin/websites.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2004-2017 Laurent Destailleur * * 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 @@ -48,15 +48,15 @@ $acts[1] = "disable"; $actl[0] = img_picto($langs->trans("Disabled"),'switch_off'); $actl[1] = img_picto($langs->trans("Activated"),'switch_on'); -$listoffset=GETPOST('listoffset'); -$listlimit=GETPOST('listlimit')>0?GETPOST('listlimit'):1000; $status = 1; -$sortfield = GETPOST("sortfield",'alpha'); -$sortorder = GETPOST("sortorder",'alpha'); -$page = GETPOST("page",'int'); -if ($page == -1 || $page == null) { $page = 0 ; } -$offset = $listlimit * $page ; +// Load variable for pagination +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; +$sortfield = GETPOST('sortfield','alpha'); +$sortorder = GETPOST('sortorder','alpha'); +$page = GETPOST('page','int'); +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +$offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -118,7 +118,7 @@ $elementList = array(); $sourceList=array(); // Actions add or modify an entry into a dictionary -if (GETPOST('actionadd') || GETPOST('actionmodify')) +if (GETPOST('actionadd','alpha') || GETPOST('actionmodify','alpha')) { $listfield=explode(',',$tabfield[$id]); $listfieldinsert=explode(',',$tabfieldinsert[$id]); @@ -138,7 +138,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify')) } // Si verif ok et action add, on ajoute la ligne - if ($ok && GETPOST('actionadd')) + if ($ok && GETPOST('actionadd','alpha')) { if ($tabrowid[$id]) { @@ -200,7 +200,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify')) } // Si verif ok et action modify, on modifie la ligne - if ($ok && GETPOST('actionmodify')) + if ($ok && GETPOST('actionmodify','alpha')) { if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; } else { $rowidcol="rowid"; } @@ -252,7 +252,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify')) //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition } -if (GETPOST('actioncancel')) +if (GETPOST('actioncancel','alpha')) { //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition } @@ -412,11 +412,11 @@ if ($id) $obj = new stdClass(); // If data was already input, we define them in obj to populate input fields. - if (GETPOST('actionadd')) + if (GETPOST('actionadd','alpha')) { foreach ($fieldlist as $key=>$val) { - if (GETPOST($val)) + if (GETPOST($val,'alpha')) $obj->$val=GETPOST($val); } } diff --git a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql index 8e4785ab4d9..ec3a945bb09 100644 --- a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql +++ b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql @@ -495,6 +495,31 @@ ALTER TABLE llx_usergroup_rights DROP INDEX fk_usergroup; ALTER TABLE llx_usergroup_rights ADD UNIQUE INDEX uk_usergroup_rights (entity, fk_usergroup, fk_id); ALTER TABLE llx_usergroup_rights ADD CONSTRAINT fk_usergroup_rights_fk_usergroup FOREIGN KEY (fk_usergroup) REFERENCES llx_usergroup (rowid); +-- For new module website + +CREATE TABLE llx_website_pages +( + rowid integer AUTO_INCREMENT NOT NULL PRIMARY KEY, + fk_website integer NOT NULL, + pageurl varchar(16) NOT NULL, + title varchar(255), + description varchar(255), + keywords varchar(255), + content mediumtext, -- text is not enough in size + status integer, + fk_user_create integer, + fk_user_modif integer, + date_creation datetime, + tms timestamp +) ENGINE=innodb; + +ALTER TABLE llx_website_pages ADD UNIQUE INDEX uk_website_pages_url (fk_website,pageurl); + +ALTER TABLE llx_website_pages ADD CONSTRAINT fk_website_pages_website FOREIGN KEY (fk_website) REFERENCES llx_website (rowid); + + +-- For new module blockedlog + CREATE TABLE llx_blockedlog ( rowid integer AUTO_INCREMENT PRIMARY KEY, diff --git a/htdocs/install/mysql/tables/llx_website_pages.key.sql b/htdocs/install/mysql/tables/llx_website_pages.key.sql index 095dffabc95..00b9439d18b 100644 --- a/htdocs/install/mysql/tables/llx_website_pages.key.sql +++ b/htdocs/install/mysql/tables/llx_website_pages.key.sql @@ -16,7 +16,7 @@ -- -- =========================================================================== -ALTER TABLE llx_website_page ADD UNIQUE INDEX uk_website_page_url (fk_website,pageurl); +ALTER TABLE llx_website_pages ADD UNIQUE INDEX uk_website_pages_url (fk_website,pageurl); -ALTER TABLE llx_website_page ADD CONSTRAINT fk_website_page_website FOREIGN KEY (fk_website) REFERENCES llx_website (rowid); +ALTER TABLE llx_website_pages ADD CONSTRAINT fk_website_pages_website FOREIGN KEY (fk_website) REFERENCES llx_website (rowid); diff --git a/htdocs/install/mysql/tables/llx_website_pages.sql b/htdocs/install/mysql/tables/llx_website_pages.sql index 69b6c417528..d45d8f06f56 100644 --- a/htdocs/install/mysql/tables/llx_website_pages.sql +++ b/htdocs/install/mysql/tables/llx_website_pages.sql @@ -17,7 +17,7 @@ -- ======================================================================== -CREATE TABLE llx_website_page +CREATE TABLE llx_website_pages ( rowid integer AUTO_INCREMENT NOT NULL PRIMARY KEY, fk_website integer NOT NULL, diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index a5c2ae4e046..d27737dd3b2 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -458,7 +458,8 @@ if ($action == 'updatecontent' || GETPOST('refreshsite') || GETPOST('refreshpage if (! is_link(dol_osencode($pathtomediasinwebsite))) { dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite); - symlink($pathtomedias, $pathtomediasinwebsite); + dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure dir for website exists + $result = symlink($pathtomedias, $pathtomediasinwebsite); } /*if (GETPOST('savevirtualhost') && $object->virtualhost != GETPOST('previewsite')) From a92effa6221b7e5f92d4764e06c7318801ad3586 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 9 Jul 2017 21:16:09 +0200 Subject: [PATCH 04/22] Fix clean test --- test/phpunit/RestAPIDocumentTest.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/phpunit/RestAPIDocumentTest.php b/test/phpunit/RestAPIDocumentTest.php index b60a7e9e833..7eb485ffbab 100644 --- a/test/phpunit/RestAPIDocumentTest.php +++ b/test/phpunit/RestAPIDocumentTest.php @@ -144,11 +144,11 @@ class RestAPIDocumentTest extends PHPUnit_Framework_TestCase echo __METHOD__.' Request POST url='.$url."\n"; - + // Send to non existant directory - + dol_delete_dir_recursive(DOL_DATA_ROOT.'/medias/tmpphpunit'); - + //$data = '{ "filename": "mynewfile.txt", "modulepart": "medias", "ref": "", "subdir": "mysubdir1/mysubdir2", "filecontent": "content text", "fileencoding": "" }'; $data = array( 'filename'=>"mynewfile.txt", @@ -158,7 +158,7 @@ class RestAPIDocumentTest extends PHPUnit_Framework_TestCase 'filecontent'=>"content text", 'fileencoding'=>"" ); - + $result = getURLContent($url, 'POST', $data, 1); echo __METHOD__.' Result for sending document: '.var_export($result, true)."\n"; echo __METHOD__.' curl_error_no: '.$result['curl_error_no']."\n"; @@ -166,11 +166,11 @@ class RestAPIDocumentTest extends PHPUnit_Framework_TestCase $this->assertNotNull($object, 'Parsing of json result must no be null'); $this->assertEquals('401', $object['error']['code']); - + // Send to existant directory - + dol_mkdir(DOL_DATA_ROOT.'/medias/tmpphpunit/tmpphpunit2'); - + $data = array( 'filename'=>"mynewfile.txt", 'modulepart'=>"medias", @@ -187,5 +187,7 @@ class RestAPIDocumentTest extends PHPUnit_Framework_TestCase $this->assertNotNull($object2, 'Parsing of json result must no be null'); $this->assertEquals($result2['curl_error_no'], ''); $this->assertEquals($result2['content'], 'true'); + + dol_delete_dir_recursive(DOL_DATA_ROOT.'/medias/tmpphpunit'); } } From fd89535037c041038fd4b70c7bede6685e215e46 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 9 Jul 2017 22:30:19 +0200 Subject: [PATCH 05/22] Debug module website --- htdocs/admin/websites.php | 16 ++-------------- htdocs/theme/eldy/ckeditor/config.js | 1 + htdocs/theme/md/ckeditor/config.js | 1 + htdocs/websites/index.php | 5 ++++- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/htdocs/admin/websites.php b/htdocs/admin/websites.php index 3b894536d04..9a12441fbb3 100644 --- a/htdocs/admin/websites.php +++ b/htdocs/admin/websites.php @@ -63,9 +63,6 @@ $pagenext = $page + 1; // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('admin')); -// This page is a generic page to edit dictionaries -// Put here declaration of dictionaries properties - // Name of SQL tables of dictionaries $tabname=array(); $tabname[1] = MAIN_DB_PREFIX."website"; @@ -341,7 +338,7 @@ if ($action == 'delete') //var_dump($elementList); /* - * Show a dictionary + * Show website list */ if ($id) { @@ -447,8 +444,7 @@ if ($id) - // List of available values in database - dol_syslog("htdocs/admin/dict", LOG_DEBUG); + // List of websites in database $resql=$db->query($sql); if ($resql) { @@ -465,14 +461,6 @@ if ($id) print ''; - // There is several pages - if ($num > $listlimit) - { - print ''; - } - // Title of lines print ''; foreach ($fieldlist as $field => $value) diff --git a/htdocs/theme/eldy/ckeditor/config.js b/htdocs/theme/eldy/ckeditor/config.js index e4a86a37293..cddbef17dd1 100644 --- a/htdocs/theme/eldy/ckeditor/config.js +++ b/htdocs/theme/eldy/ckeditor/config.js @@ -15,6 +15,7 @@ CKEDITOR.editorConfig = function( config ) //config.height = '300px'; //config.resize_dir = 'vertical'; // horizontal, vertical, both config.removePlugins = 'elementspath,save'; // config.removePlugins = 'elementspath,save,font'; + //config.extraPlugins = 'docprops,scayt,showprotected'; config.removeDialogTabs = 'flash:advanced'; // config.removeDialogTabs = 'flash:advanced;image:Link'; config.protectedSource.push( /<\?[\s\S]*?\?>/g ); // Prevent PHP Code to be formatted //config.menu_groups = 'clipboard,table,anchor,link,image'; // for context menu 'clipboard,form,tablecell,tablecellproperties,tablerow,tablecolumn,table,anchor,link,image,flash,checkbox,radio,textfield,hiddenfield,imagebutton,button,select,textarea' diff --git a/htdocs/theme/md/ckeditor/config.js b/htdocs/theme/md/ckeditor/config.js index a6508e62a88..e0374f6b271 100644 --- a/htdocs/theme/md/ckeditor/config.js +++ b/htdocs/theme/md/ckeditor/config.js @@ -15,6 +15,7 @@ CKEDITOR.editorConfig = function( config ) //config.height = '300px'; //config.resize_dir = 'vertical'; // horizontal, vertical, both config.removePlugins = 'elementspath,save'; // config.removePlugins = 'elementspath,save,font'; + //config.extraPlugins = 'docprops,scayt,showprotected'; config.removeDialogTabs = 'flash:advanced'; // config.removeDialogTabs = 'flash:advanced;image:Link'; config.protectedSource.push( /<\?[\s\S]*?\?>/g ); // Prevent PHP Code to be formatted //config.menu_groups = 'clipboard,table,anchor,link,image'; // for context menu 'clipboard,form,tablecell,tablecellproperties,tablerow,tablecolumn,table,anchor,link,image,flash,checkbox,radio,textfield,hiddenfield,imagebutton,button,select,textarea' diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index d27737dd3b2..b2b8662fe08 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -1090,7 +1090,10 @@ if ($action == 'preview') $out.=$csscontent; $out.=''."\n"; - $out.=$objectpage->content."\n"; + // Replace php code + $content = preg_replace('/<\?php.*\?>/ims', '...php...', $objectpage->content); + + $out.=$content."\n"; $out.=''; From bb2dc59c56163a35027408818e64bde4fa851302 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 10 Jul 2017 11:29:09 +0200 Subject: [PATCH 06/22] More complete request to clean --- htdocs/install/mysql/migration/repair.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/install/mysql/migration/repair.sql b/htdocs/install/mysql/migration/repair.sql index f67869f67ba..f2e5066a066 100755 --- a/htdocs/install/mysql/migration/repair.sql +++ b/htdocs/install/mysql/migration/repair.sql @@ -330,7 +330,7 @@ drop table tmp_c_shipment_mode; -- Restore id of user on link for payment of expense report drop table tmp_bank_url_expense_user; create table tmp_bank_url_expense_user (select e.fk_user_author, bu2.fk_bank from llx_expensereport as e, llx_bank_url as bu2 where bu2.url_id = e.rowid and bu2.type = 'payment_expensereport'); -update llx_bank_url as bu set url_id = (select e.fk_user_author from tmp_bank_url_expense_user as e where e.fk_bank = bu.fk_bank) where bu.url_id = 0 and bu.type ='user'; +update llx_bank_url as bu set url_id = (select e.fk_user_author from tmp_bank_url_expense_user as e where e.fk_bank = bu.fk_bank) where (bu.url_id = 0 OR bu.url_id IS NULL) and bu.type ='user'; drop table tmp_bank_url_expense_user; From f85fcbd2161dedf23cfa75d710c4872418b9019b Mon Sep 17 00:00:00 2001 From: fappels Date: Mon, 10 Jul 2017 12:47:21 +0200 Subject: [PATCH 07/22] Fix categorie navigation --- htdocs/categories/class/categorie.class.php | 2 +- htdocs/categories/viewcat.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index db3364ff04d..1b292b9e470 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -133,7 +133,7 @@ class Categorie extends CommonObject ); public $element='category'; - public $table_element='categories'; + public $table_element='categorie'; public $fk_parent; public $label; diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php index 11aff01dc99..1c6186d5df4 100644 --- a/htdocs/categories/viewcat.php +++ b/htdocs/categories/viewcat.php @@ -35,14 +35,14 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; $langs->load("categories"); $id=GETPOST('id','int'); -$ref=GETPOST('ref'); +$label=GETPOST('label'); $type=GETPOST('type'); $action=GETPOST('action','aZ09'); $confirm=GETPOST('confirm'); $removeelem = GETPOST('removeelem','int'); $elemid=GETPOST('elemid'); -if ($id == "") +if ($id == "" && $label == "") { dol_print_error('','Missing parameter id'); exit(); @@ -52,7 +52,7 @@ if ($id == "") $result = restrictedArea($user, 'categorie', $id, '&category'); $object = new Categorie($db); -$result=$object->fetch($id); +$result=$object->fetch($id, $label); $object->fetch_optionals($id,$extralabels); if ($result <= 0) { @@ -195,7 +195,7 @@ $head = categories_prepare_head($object,$type); dol_fiche_head($head, 'card', $title, -1, 'category'); $linkback = ''.$langs->trans("BackToList").''; - +$object->next_prev_filter=" type = ".$object->type; $object->ref = $object->label; $morehtmlref='
'.$langs->trans("Root").' >> '; $ways = $object->print_all_ways(" >> ", '', 1); @@ -205,7 +205,7 @@ foreach ($ways as $way) } $morehtmlref.='
'; -dol_banner_tab($object, 'ref', $linkback, ($user->societe_id?0:1), 'ref', 'ref', $morehtmlref, '', 0, '', '', 1); +dol_banner_tab($object, 'label', $linkback, ($user->societe_id?0:1), 'label', 'label', $morehtmlref, '', 0, '', '', 1); /* From 1ab3e0c3fa03bfbfb7e998e30c43981ba11feee9 Mon Sep 17 00:00:00 2001 From: BENKE Charlene Date: Mon, 10 Jul 2017 14:00:32 +0200 Subject: [PATCH 08/22] if no suppliers selected, no subprice yet --- htdocs/supplier_proposal/class/supplier_proposal.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index 0c8410213af..1d27e7c4986 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -2841,7 +2841,7 @@ class SupplierProposalLine extends CommonObjectLine $sql.= " ".price2num($this->localtax2_tx).","; $sql.= " '".$this->localtax1_type."',"; $sql.= " '".$this->localtax2_type."',"; - $sql.= " ".price2num($this->subprice).","; + $sql.= " ".(!empty($this->subprice)?price2num($this->subprice):"null").","; $sql.= " ".price2num($this->remise_percent).","; $sql.= " ".(isset($this->info_bits)?"'".$this->info_bits."'":"null").","; $sql.= " ".price2num($this->total_ht).","; From 8c287c02ca2fb9d70f778ba302eda278310f9e9f Mon Sep 17 00:00:00 2001 From: AlainRnet Date: Mon, 10 Jul 2017 15:41:26 +0200 Subject: [PATCH 09/22] Update card.php Limitation of the number of characters that is not limited in the third card as described here: https://www.dolibarr.fr/forum/5-bugs-sur-la-version-cvs-ou-demo/59229-taille-limitee-de-l-adesse-mail-des-contacts --- htdocs/contact/card.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index fbd27b0d841..d5854297f43 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -625,7 +625,7 @@ else // EMail if (($objsoc->typent_code == 'TE_PRIVATE' || ! empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->email)) == 0) $object->email = $objsoc->email; // Predefined with third party print '
'; - print ''; + print ''; if (! empty($conf->mailing->enabled)) { print ''; @@ -860,7 +860,7 @@ else // EMail print ''; - print ''; + print ''; if (! empty($conf->mailing->enabled)) { $langs->load("mails"); From be09c911ce5a904d376b961623f7f65ab8a7a4a6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 10 Jul 2017 23:44:46 +0200 Subject: [PATCH 10/22] Debug module websites --- htdocs/admin/websites.php | 2 +- .../install/mysql/migration/5.0.0-6.0.0.sql | 6 +- ...pages.key.sql => llx_website_page.key.sql} | 4 +- ...website_pages.sql => llx_website_page.sql} | 2 +- htdocs/langs/en_US/website.lang | 1 + htdocs/websites/class/websitepage.class.php | 2 +- htdocs/websites/index.php | 62 +++++++++++++------ 7 files changed, 53 insertions(+), 26 deletions(-) rename htdocs/install/mysql/tables/{llx_website_pages.key.sql => llx_website_page.key.sql} (80%) rename htdocs/install/mysql/tables/{llx_website_pages.sql => llx_website_page.sql} (97%) diff --git a/htdocs/admin/websites.php b/htdocs/admin/websites.php index 9a12441fbb3..66776220d32 100644 --- a/htdocs/admin/websites.php +++ b/htdocs/admin/websites.php @@ -259,7 +259,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes') // delete if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; } else { $rowidcol="rowid"; } - $sql = "DELETE from ".MAIN_DB_PREFIX."website_pages WHERE fk_website ='".$rowid."'"; + $sql = "DELETE from ".MAIN_DB_PREFIX."website_page WHERE fk_website ='".$rowid."'"; $result = $db->query($sql); $sql = "DELETE from ".MAIN_DB_PREFIX."website WHERE rowid ='".$rowid."'"; diff --git a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql index ec3a945bb09..0137353f714 100644 --- a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql +++ b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql @@ -497,7 +497,7 @@ ALTER TABLE llx_usergroup_rights ADD CONSTRAINT fk_usergroup_rights_fk_usergroup -- For new module website -CREATE TABLE llx_website_pages +CREATE TABLE llx_website_page ( rowid integer AUTO_INCREMENT NOT NULL PRIMARY KEY, fk_website integer NOT NULL, @@ -513,9 +513,9 @@ CREATE TABLE llx_website_pages tms timestamp ) ENGINE=innodb; -ALTER TABLE llx_website_pages ADD UNIQUE INDEX uk_website_pages_url (fk_website,pageurl); +ALTER TABLE llx_website_page ADD UNIQUE INDEX uk_website_page_url (fk_website,pageurl); -ALTER TABLE llx_website_pages ADD CONSTRAINT fk_website_pages_website FOREIGN KEY (fk_website) REFERENCES llx_website (rowid); +ALTER TABLE llx_website_page ADD CONSTRAINT fk_website_page_website FOREIGN KEY (fk_website) REFERENCES llx_website (rowid); -- For new module blockedlog diff --git a/htdocs/install/mysql/tables/llx_website_pages.key.sql b/htdocs/install/mysql/tables/llx_website_page.key.sql similarity index 80% rename from htdocs/install/mysql/tables/llx_website_pages.key.sql rename to htdocs/install/mysql/tables/llx_website_page.key.sql index 00b9439d18b..14488e588dc 100644 --- a/htdocs/install/mysql/tables/llx_website_pages.key.sql +++ b/htdocs/install/mysql/tables/llx_website_page.key.sql @@ -16,7 +16,7 @@ -- -- =========================================================================== -ALTER TABLE llx_website_pages ADD UNIQUE INDEX uk_website_pages_url (fk_website,pageurl); +ALTER TABLE llx_website_page ADD UNIQUE INDEX uk_website_page_url (fk_website, pageurl); -ALTER TABLE llx_website_pages ADD CONSTRAINT fk_website_pages_website FOREIGN KEY (fk_website) REFERENCES llx_website (rowid); +ALTER TABLE llx_website_page ADD CONSTRAINT fk_website_page_website FOREIGN KEY (fk_website) REFERENCES llx_website (rowid); diff --git a/htdocs/install/mysql/tables/llx_website_pages.sql b/htdocs/install/mysql/tables/llx_website_page.sql similarity index 97% rename from htdocs/install/mysql/tables/llx_website_pages.sql rename to htdocs/install/mysql/tables/llx_website_page.sql index d45d8f06f56..69b6c417528 100644 --- a/htdocs/install/mysql/tables/llx_website_pages.sql +++ b/htdocs/install/mysql/tables/llx_website_page.sql @@ -17,7 +17,7 @@ -- ======================================================================== -CREATE TABLE llx_website_pages +CREATE TABLE llx_website_page ( rowid integer AUTO_INCREMENT NOT NULL PRIMARY KEY, fk_website integer NOT NULL, diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index abb7f7e56d3..cc2f31143ce 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -4,6 +4,7 @@ WebsiteSetupDesc=Create here as much entry as number of different websites you n DeleteWebsite=Delete website ConfirmDeleteWebsite=Are you sure you want to delete this web site. All its pages and content will also be removed. WEBSITE_PAGENAME=Page name/alias +WEBSITE_HTML_HEADER=HTML Header WEBSITE_CSS_URL=URL of external CSS file WEBSITE_CSS_INLINE=CSS content PageNameAliasHelp=Name or alias of the page.
This alias is also used to forge a SEO URL when website is read from a Virtual host of a Web server (like Apacke, Nginx, ...). Use the button "%s" to edit this alias. diff --git a/htdocs/websites/class/websitepage.class.php b/htdocs/websites/class/websitepage.class.php index 99fd4d64603..4f9dc58c615 100644 --- a/htdocs/websites/class/websitepage.class.php +++ b/htdocs/websites/class/websitepage.class.php @@ -129,7 +129,7 @@ class WebsitePage extends CommonObject $sql.= 'content,'; $sql.= 'status,'; $sql.= 'date_creation,'; - $sql.= 'date_modification'; + $sql.= 'tms'; $sql .= ') VALUES ('; $sql .= ' '.(! isset($this->fk_website)?'NULL':$this->fk_website).','; $sql .= ' '.(! isset($this->pageurl)?'NULL':"'".$this->db->escape($this->pageurl)."'").','; diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index b2b8662fe08..2c9c364edac 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -129,6 +129,7 @@ if ($pageid > 0 && $action != 'add') global $dolibarr_main_data_root; $pathofwebsite=$dolibarr_main_data_root.'/websites/'.$website; +$filehtmlheader=$pathofwebsite.'/header.html'; $filecss=$pathofwebsite.'/styles.css.php'; $filetpl=$pathofwebsite.'/page'.$pageid.'.tpl.php'; $fileindex=$pathofwebsite.'/index.php'; @@ -240,25 +241,30 @@ if ($action == 'delete') // Update css if ($action == 'updatecss') { - //$db->begin(); - $res = $object->fetch(0, $website); - /* - $res = $object->update($user); - if ($res > 0) - { - $db->commit(); - $action=''; - } - else + // Html header file + $htmlheadercontent = ''."\n"; + $htmlheadercontent.= ''."\n"; + $htmlheadercontent.= ''."\n"; + $htmlheadercontent.= GETPOST('WEBSITE_HTML_HEADER'); + + dol_syslog("Save file css into ".$filehtmlheader); + + dol_mkdir($pathofwebsite); + $result = file_put_contents($filehtmlheader, $htmlheadercontent); + if (! empty($conf->global->MAIN_UMASK)) + @chmod($filehtmlheader, octdec($conf->global->MAIN_UMASK)); + + if (! $result) { $error++; - $db->rollback(); - }*/ + setEventMessages('Failed to write file '.$filehtmlheader, null, 'errors'); + } + // Css file $csscontent = ''."\n"; - $csscontent.= ''."\n"; + $csscontent.= ''."\n"; $csscontent.= '"."\n"; @@ -278,6 +284,7 @@ if ($action == 'updatecss') setEventMessages('Failed to write file '.$filecss, null, 'errors'); } + if (! $error) { setEventMessages($langs->trans("Saved"), null, 'mesgs'); @@ -310,7 +317,7 @@ if ($action == 'setashome') dol_delete_file($fileindex); $indexcontent = ''."\n"; $result = file_put_contents($fileindex, $indexcontent); @@ -406,6 +413,7 @@ if ($action == 'updatemeta') $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; $tplcontent.= '
'."\n"; + $tplcontent.= ''.dol_escape_htmltag($objectpage->title).''."\n"; $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; @@ -414,8 +422,10 @@ if ($action == 'updatemeta') $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; + $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; - $tplcontent.= ''.dol_escape_htmltag($objectpage->title).''."\n"; + $tplcontent.= ''."\n"; + $tplcontent.= 'ref.'/header.html"); ?>'."\n"; $tplcontent.= '
'."\n"; $tplcontent.= ''."\n"; @@ -561,6 +571,7 @@ if ($action == 'updatecontent' || GETPOST('refreshsite') || GETPOST('refreshpage $tplcontent.= "// END PHP ?>\n"; $tplcontent.= ''."\n"; $tplcontent.= '
'."\n"; + $tplcontent.= ''.dol_escape_htmltag($objectpage->title).''."\n"; $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; @@ -568,8 +579,10 @@ if ($action == 'updatecontent' || GETPOST('refreshsite') || GETPOST('refreshpage $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; - $tplcontent.= ''."\n"; - $tplcontent.= ''.dol_escape_htmltag($objectpage->title).''."\n"; + $tplcontent.= ''."\n"; + $tplcontent.= ''."\n"; + $tplcontent.= ''."\n"; + $tplcontent.= 'ref.'/header.html"); ?>'."\n"; $tplcontent.= '
'."\n"; $tplcontent.= ''."\n"; @@ -940,6 +953,11 @@ if ($action == 'editcss') print '
'; + $htmlheader = @file_get_contents($filehtmlheader); + // Clean the php css file to remove php code and get only html part + $htmlheader = preg_replace('//s', '', $htmlheader); + + $csscontent = @file_get_contents($filecss); // Clean the php css file to remove php code and get only css part $csscontent = preg_replace('//s', '', $csscontent); @@ -958,11 +976,19 @@ if ($action == 'editcss') print '
'; + print ''; + /*print ''; - print ''; + print ''; print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + //print ''; + print ''; print ''; print ''; print ''; @@ -986,9 +1010,11 @@ elseif (! empty($module)) print ''; print ''; print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + //print ''; + print ''; print ''; print ''; - print ''; - print ''; - print ''; + /*print '';*/ + print ''; print ''; } -/*if (! empty($arrayfields['u.statut']['checked'])) +/*if (! empty($arrayfields['t.statut']['checked'])) { // Status print ''; diff --git a/htdocs/modulebuilder/template/sql/llx_myobject.key.sql b/htdocs/modulebuilder/template/sql/llx_myobject.key.sql index 812a98090af..4822d7c3ac4 100644 --- a/htdocs/modulebuilder/template/sql/llx_myobject.key.sql +++ b/htdocs/modulebuilder/template/sql/llx_myobject.key.sql @@ -14,6 +14,9 @@ -- along with this program. If not, see . -ALTER TABLE llx_myobject ADD UNIQUE INDEX uk_fk_othertable (fk_othertable); ---ALTER TABLE llx_myobject ADD CONSTRAINT llx_mytable_field_id FOREIGN KEY (fk_field) REFERENCES llx_myOthertable(rowid); +-- BEGIN MODULEBUILDER INDEXES +ALTER TABLE llx_myobject ADD UNIQUE INDEX idx_fieldobject (fieldobject); +-- END MODULEBUILDER INDEXES + +--ALTER TABLE llx_myobject ADD CONSTRAINT llx_myobject_field_id FOREIGN KEY (fk_field) REFERENCES llx_myotherobject(rowid); diff --git a/htdocs/modulebuilder/template/sql/llx_myobject.sql b/htdocs/modulebuilder/template/sql/llx_myobject.sql index 8cba239766f..b5810f0f227 100644 --- a/htdocs/modulebuilder/template/sql/llx_myobject.sql +++ b/htdocs/modulebuilder/template/sql/llx_myobject.sql @@ -13,9 +13,14 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . + CREATE TABLE llx_myobject( rowid INTEGER AUTO_INCREMENT PRIMARY KEY, + -- BEGIN MODULEBUILDER FIELDS entity INTEGER DEFAULT 1 NOT NULL, - fk_othertable INTEGER NOT NULL, - name VARCHAR(189) -); + label VARCHAR(255), + datec DATETIME NOT NULL, + tms TIMESTAMP NOT NULL, + status INTEGER + -- END MODULEBUILDER FIELDS +) ENGINE=innodb; \ No newline at end of file From 40b3ae2a1528340ec00d033233f513264d53c9f8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 12 Jul 2017 11:52:07 +0200 Subject: [PATCH 18/22] Debug modulebuilder --- htdocs/core/class/html.formfile.class.php | 6 +- htdocs/core/lib/modulebuilder.lib.php | 164 ++++++++++++--- htdocs/langs/en_US/modulebuilder.lang | 2 +- htdocs/modulebuilder/index.php | 16 +- .../template/class/myobject.class.php | 4 +- .../modulebuilder/template/myobject_list.php | 192 ++++++++++-------- 6 files changed, 259 insertions(+), 125 deletions(-) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index a5ccb33f084..040ae1ba96e 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -314,7 +314,7 @@ class FormFile if (preg_match('/massfilesarea_/', $modulepart)) { - $out.='

'; + $out.='

'."\n"; $title=$langs->trans("MassFilesArea").' ('.$langs->trans("Hide").')'; $title.=''; +// Build and execute select +// -------------------------------------------------------------------- $sql = 'SELECT '; foreach($object->fields as $key => $val) { @@ -275,15 +261,36 @@ if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && exit; } + +// Output page +// -------------------------------------------------------------------- + llxHeader('', $title, $help_url); +// Example : Adding jquery code +print ''; + $arrayofselected=is_array($toselect)?$toselect:array(); $param=''; if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; -if ($search_field1 != '') $param.= '&search_field1='.urlencode($search_field1); -if ($search_field2 != '') $param.= '&search_field2='.urlencode($search_field2); +foreach($search as $key => $val) +{ + $param.= '&search_'.$key.'='.urlencode($search[$key]); +} if ($optioncss != '') $param.='&optioncss='.$optioncss; // Add $param from extra fields foreach ($search_array_options as $key => $val) @@ -345,10 +352,16 @@ print '
'; - print_fleche_navigation($page, $_SERVER["PHP_SELF"], '', ($num > $listlimit), ''); - print '
email).'">email).'">
email).'">email).'">
'; print $langs->trans('WEBSITE_CSS_INLINE'); print ''; - print ''; print '
'; + print $langs->trans('WEBSITE_HTML_HEADER'); + print ''; + print ''; + print '
'; print $langs->trans('WEBSITE_CSS_URL'); print ''; From c75db29ff2a67345b78bf4cad4e01cf8a661253f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 11 Jul 2017 12:54:03 +0200 Subject: [PATCH 11/22] Fix warning when module position is not correct --- htdocs/core/class/menubase.class.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/menubase.class.php b/htdocs/core/class/menubase.class.php index 137a5517231..431c5d19eeb 100644 --- a/htdocs/core/class/menubase.class.php +++ b/htdocs/core/class/menubase.class.php @@ -402,7 +402,8 @@ class Menubase } /** - * Load entries found from database in this->newmenu array. + * Load entries found from database (and stored into $tabMenu) in $this->newmenu array. + * Warning: Entries in $tabMenu must have child after parent * * @param Menu $newmenu Menu array to complete (in most cases, it's empty, may be already initialized with some menu manager like eldy) * @param string $mymainmenu Value for mainmenu to filter menu to load (often $_SESSION["mainmenu"]) @@ -435,10 +436,10 @@ class Menubase // We initialize newmenu with first already found menu entries $this->newmenu = $newmenu; - // Now edit this->newmenu->list to add entries found into tabMenu that are childs of mainmenu claimed, using the fk_menu link (old method) + // Now complete $this->newmenu->list to add entries found into $tabMenu that are childs of mainmenu=$menutopid, using the fk_menu link that is int (old method) $this->recur($tabMenu, $menutopid, 1); - // Now update this->newmenu->list when fk_menu value is -1 (left menu added by modules with no top menu) + // Now complete $this->newmenu->list when fk_menu value is -1 (left menu added by modules with no top menu) foreach($tabMenu as $key => $val) { //var_dump($tabMenu); @@ -479,6 +480,10 @@ class Menubase } //print 'We must insert menu entry between entry '.$lastid.' and '.$nextid.'
'; if ($found) $this->newmenu->insert($lastid, $val['url'], $val['titre'], $searchlastsub, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position']); + else { + dol_syslog("Error. Modules ".$val['module']." has defined a menu entry with a parent='fk_mainmenu=".$val['fk_leftmenu'].",fk_leftmenu=".$val['fk_leftmenu']."' and position=".$val['position'].'. The parent was not found. May be you forget it into your definition of menu, or may be the parent has a "position" that is after the child (fix field "position" of parent or child in this case).', LOG_WARNING); + //print "Parent menu not found !!
"; + } } } } @@ -494,7 +499,7 @@ class Menubase * @param string $myleftmenu Value for left that defined leftmenu * @param int $type_user Looks for menu entry for 0=Internal users, 1=External users * @param string $menu_handler Name of menu_handler used ('auguria', 'eldy'...) - * @param array $tabMenu Array to store new entries found (in most cases, it's empty, but may be alreay filled) + * @param array $tabMenu Array to store new entries found (in most cases, it's empty, but may be alreay filled) * @return int >0 if OK, <0 if KO */ function menuLoad($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu) @@ -610,6 +615,11 @@ class Menubase $a++; } $this->db->free($resql); + + // Currently $tabMenu is sorted on position. + // If a child have a position lower that its parent, we can make a loop to fix this here, but we prefer to show a warning + // into the leftMenuCharger later to avoid useless operations. + return 1; } else @@ -622,7 +632,7 @@ class Menubase /** * Complete this->newmenu with menu entry found in $tab * - * @param array $tab Tab array + * @param array $tab Tab array with all menu entries * @param int $pere Id of parent * @param int $level Level * @return void From 90dcd3d30db51398ccfc594ff2ee3f79b829ed4e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 11 Jul 2017 13:25:41 +0200 Subject: [PATCH 12/22] Look and feel v6 --- htdocs/societe/price.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/societe/price.php b/htdocs/societe/price.php index 5146e3ad6a5..d7b683f92e7 100644 --- a/htdocs/societe/price.php +++ b/htdocs/societe/price.php @@ -187,7 +187,7 @@ if (! empty($conf->notification->enabled)) $langs->load("mails"); $head = societe_prepare_head($object); -dol_fiche_head($head, 'price', $langs->trans("ThirdParty"), 0, 'company'); +dol_fiche_head($head, 'price', $langs->trans("ThirdParty"), -1, 'company'); $linkback = ''.$langs->trans("BackToList").''; @@ -200,11 +200,11 @@ print ''; if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field { - print ''; + print ''; } if ($object->client) { - print '
' . $langs->trans('Prefix') . '' . $object->prefix_comm . '
' . $langs->trans('Prefix') . '' . $object->prefix_comm . '
'; + print '
'; print $langs->trans('CustomerCode') . ''; print $object->code_client; if ($object->check_codeclient() != 0) @@ -213,7 +213,7 @@ if ($object->client) { } if ($object->fournisseur) { - print '
'; + print '
'; print $langs->trans('SupplierCode') . ''; print $object->code_fournisseur; if ($object->check_codefournisseur() != 0) From e1d9dfc862c21ca279eb592db8472f0ae3ce31de Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 11 Jul 2017 15:12:01 +0200 Subject: [PATCH 13/22] Complete example of template --- .../template/core/modules/modMyModule.class.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php index 33c52d58bea..fbfffba07ed 100644 --- a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php +++ b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php @@ -288,6 +288,12 @@ class modMyModule extends DolibarrModules $this->_load_tables('/mymodule/sql/'); + // Create extrafields + include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + $extrafields = new ExtraFields($this->db); + //$result1=$extrafields->addExtraField('myattr1', "New Attr 1 label", 'boolean', 1, 3, 'thirdparty'); + //$result2=$extrafields->addExtraField('myattr2', "New Attr 2 label", 'string', 1, 10, 'project'); + return $this->_init($sql, $options); } From cbde99b4197aa6cbec5d7dae01586cd35d0cf946 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 11 Jul 2017 15:50:20 +0200 Subject: [PATCH 14/22] More complete exemple --- .../modulebuilder/template/core/modules/modMyModule.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php index fbfffba07ed..cd3fb22be80 100644 --- a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php +++ b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php @@ -99,7 +99,7 @@ class modMyModule extends DolibarrModules ); // Data directories to create when module is enabled. - // Example: this->dirs = array("/mymodule/temp"); + // Example: this->dirs = array("/mymodule/temp","/mymodule/subdir"); $this->dirs = array(); // Config pages. Put here list of php page, stored into mymodule/admin directory, to use to setup module. From ceeb9d7f1b93046d84d6477a84b4ffad08eff68b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 11 Jul 2017 20:47:49 +0200 Subject: [PATCH 15/22] Debug modulebuilder --- htdocs/langs/en_US/modulebuilder.lang | 2 + htdocs/modulebuilder/index.php | 231 +++++++++++++----- .../template/class/myobject.class.php | 20 +- .../modulebuilder/template/myobject_list.php | 24 +- 4 files changed, 198 insertions(+), 79 deletions(-) diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index 8fab0a7b07f..5a3470aebce 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -38,3 +38,5 @@ PathToModulePackage=Path to zip of module/application package PathToModuleDocumentation=Path to file of module/application documentation SpaceOrSpecialCharAreNotAllowed=Spaces or special characters are not allowed. FileNotYetGenerated=File not yet generated +SpecificationFile=File with business rules +ConfirmDeleteProperty=Are you sure you want to delete the property %s ? This will change code in PHP class but also remove column from table definition of object. \ No newline at end of file diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 2547b893055..a1c30b7c94a 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -37,9 +37,10 @@ $cancel=GETPOST('cancel','alpha'); $module=GETPOST('module','alpha'); $tab=GETPOST('tab','aZ09'); $tabobj=GETPOST('tabobj','alpha'); +$propertykey=GETPOST('propertykey','alpha'); if (empty($module)) $module='initmodule'; if (empty($tab)) $tab='description'; -if (empty($tabobj)) $tabobj='newobject'; +if (empty($tabobj)) $tabobj='newobjectifnoobj'; $file=GETPOST('file','alpha'); $modulename=dol_sanitizeFileName(GETPOST('modulename','alpha')); @@ -58,6 +59,7 @@ $FILEFLAG='modulebuilder.txt'; $now=dol_now(); + /* * Actions */ @@ -320,6 +322,29 @@ if ($dirins && $action == 'confirm_deleteobject' && $objectname) $tabobj = 'deleteobject'; } +if ($dirins && $action == 'confirm_deleteproperty' && $propertykey) +{ + if (! $error) + { + $modulelowercase=strtolower($module); + $objectlowercase=strtolower($objectname); + + // File of class + $fileforclass = $dirins.'/'.$modulelowercase.'/class/'.$objectlowercase.'.class.php'; + + // TODO + + // File of sql + $fileforsql = $dirins.'/'.$modulelowercase.'/sql/'.$objectlowercase.'.sql'; + $fileforsqlkey = $dirins.'/'.$modulelowercase.'/sql/'.$objectlowercase.'.key.sql'; + + + // TODO + } +} + + + if ($dirins && $action == 'generatepackage') { $modulelowercase=strtolower($module); @@ -838,9 +863,11 @@ elseif (! empty($module)) $h++; $listofobject = dol_dir_list($dir, 'files', 0, '\.txt$'); + $firstobjectname=''; foreach($listofobject as $fileobj) { $objectname = preg_replace('/\.txt$/', '', $fileobj['name']); + if (empty($firstobjectname)) $firstobjectname = $objectname; $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.'&tabobj='.$objectname; $head3[$h][1] = $objectname; @@ -853,6 +880,12 @@ elseif (! empty($module)) $head3[$h][2] = 'deleteobject'; $h++; + // If tabobj was not defined, then we check if there is one obj. If yes, we force on it, if no, we will show tab to create new objects. + if ($tabobj == 'newobjectifnoobj') + { + if ($firstobjectname) $tabobj=$firstobjectname; + else $tabobj = 'newobject'; + } dol_fiche_head($head3, $tabobj, '', -1, ''); @@ -888,92 +921,168 @@ elseif (! empty($module)) } else { - try { - $pathtoclass = strtolower($module).'/class/'.strtolower($tabobj).'.class.php'; - $pathtoapi = strtolower($module).'/class/api_'.strtolower($tabobj).'.class.php'; - $pathtolist = strtolower($module).'/'.strtolower($tabobj).'_list.class.php'; - $pathtocard = strtolower($module).'/'.strtolower($tabobj).'_card.class.php'; - print ' '.$langs->trans("ClassFile").' : '.$pathtoclass.'
'; - print ' '.$langs->trans("ApiClassFile").' : '.$pathtoapi.'
'; - print ' '.$langs->trans("PageForList").' : '.$pathtolist.'
'; - print ' '.$langs->trans("PageForCreateEditView").' : '.$pathtocard.'
'; + if ($action == 'deleteproperty') + { + $formconfirm = $form->formconfirm( + $_SERVER["PHP_SELF"].'?propertykey='.urlencode(GETPOST('propertykey','alpha')).'&objectname='.urlencode($objectname).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj), + $langs->trans('Delete'), $langs->trans('ConfirmDeleteProperty', GETPOST('propertykey','alpha')), 'confirm_deleteproperty', '', 0, 1 + ); - $result = dol_include_once($pathtoclass); - $tmpobjet = new $tabobj($db); + // Print form confirm + print $formconfirm; + } - $reflector = new ReflectionClass($tabobj); - $properties = $reflector->getProperties(); // Can also use get_object_vars - $propdefault = $reflector->getDefaultProperties(); // Can also use get_object_vars - //$propstat = $reflector->getStaticProperties(); + if ($action != 'editfile' || empty($file)) + { + try { + $pathtoclass = strtolower($module).'/class/'.strtolower($tabobj).'.class.php'; + $pathtoapi = strtolower($module).'/class/api_'.strtolower($tabobj).'.class.php'; + $pathtolist = strtolower($module).'/'.strtolower($tabobj).'_list.php'; + $pathtocard = strtolower($module).'/'.strtolower($tabobj).'_card.php'; + print ' '.$langs->trans("ClassFile").' : '.$pathtoclass.''; + print ' '.img_picto($langs->trans("Edit"), 'edit').''; + print '
'; + print ' '.$langs->trans("ApiClassFile").' : '.$pathtoapi.''; + print ' '.img_picto($langs->trans("Edit"), 'edit').''; + print '
'; + print ' '.$langs->trans("PageForList").' : '.$pathtolist.''; + print ' '.img_picto($langs->trans("Edit"), 'edit').''; + print '
'; + print ' '.$langs->trans("PageForCreateEditView").' : '.$pathtocard.''; + print ' '.img_picto($langs->trans("Edit"), 'edit').''; + print '
'; - print load_fiche_titre($langs->trans("Properties"), '', ''); + $result = dol_include_once($pathtoclass); + $tmpobjet = new $tabobj($db); - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; + $reflector = new ReflectionClass($tabobj); + $properties = $reflector->getProperties(); // Can also use get_object_vars + $propdefault = $reflector->getDefaultProperties(); // Can also use get_object_vars + //$propstat = $reflector->getStaticProperties(); - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - foreach($properties as $propkey => $propval) - { - if ($propval->class == $tabobj) + print load_fiche_titre($langs->trans("Properties"), '', ''); + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print '
'.$langs->trans("Property"); - print ' ('.$langs->trans("Example").')'; - print ''.$langs->trans("Comment").''.$langs->trans("Type").''.$langs->trans("DefaultValue").'
'; - print ''; - print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $properties = $tmpobjet->fields; + + foreach($properties as $propkey => $propval) { - $propname=$propval->getName(); + /* If from Reflection + if ($propval->class == $tabobj) + { + $propname=$propval->getName(); + $comment=$propval->getDocComment(); + $type=gettype($tmpobjet->$propname); + $default=$propdefault[$propname]; + // Discard generic properties + if (in_array($propname, array('element', 'childtables', 'table_element', 'table_element_line', 'class_element_line', 'isnolinkedbythird', 'ismultientitymanaged'))) continue; - // Discard generic properties - if (in_array($propname, array('element', 'childtables', 'table_element', 'table_element_line', 'class_element_line', 'isnolinkedbythird', 'ismultientitymanaged'))) continue; + // Keep or not lines + if (in_array($propname, array('fk_element', 'lines'))) continue; + }*/ - // Keep or not lines - if (in_array($propname, array('fk_element', 'lines'))) continue; + $propname=$propkey; + $proplabel=$propval['label']; + $proptype=$propval['type']; + $propposition=$propval['position']; + $propdefault=$propval['default']; + $propindex=$propval['index']; + $propcomment=$propval['comment']; + print ''; - print ''; print ''; print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; } + print '
'.$langs->trans("Property"); + print ' ('.$langs->trans("Example").')'; + print ''.$langs->trans("Label").''.$langs->trans("Type").''.$langs->trans("Position").''.$langs->trans("DefaultValue").''.$langs->trans("Index").''.$langs->trans("Comment").'
'; + print ''; + print '
'; + print ''; print $propname; print ''; - print $propval->getDocComment(); + print $proplabel; print ''; - print gettype($tmpobjet->$propname); + print $proptype; print ''; - print $propdefault[$propname]; + print $propposition; print ''; - + print $propdefault; print ''; + print yn($propindex); + print ''; + print $propcomment; + print ''; + print ''.img_delete().''; + print '
'; + + print '
'; } - print '
'; + catch(Exception $e) + { + print $e->getMessage(); + } + } + else + { + $fullpathoffile=dol_buildpath($file, 0); + + $content = file_get_contents($fullpathoffile); + + // New module + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + + $doleditor=new DolEditor('editfilecontent', $content, '', '600', 'Full', 'In', true, false, false, 0, '99%'); + print $doleditor->Create(1, '', false); + print '
'; + print '
'; + print ''; + print '   '; + print ''; + print '
'; print '
'; } - catch(Exception $e) - { - print $e->getMessage(); - } } } diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index 9ef593367c9..4c85a6e5a86 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -52,22 +52,24 @@ class MyObject extends CommonObject * @var array Does myobject support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe */ protected $ismultientitymanaged = 1; - - /** - * @var string String with name of icon for myobject - */ + * @var string String with name of icon for myobject + */ public $picto = 'myobject'; - /** - * @var int Entity Id - */ - public $entity; + /* BEGIN PROPERTY FIELDS - Do not remove this comment */ /** * @var array Array with all fields and their property */ - public $fields; + public $fields=array( + 'ref'=>array('type'=>'string','label'=>'Ref','position'=>10,'index'=>true,'comment'=>'Reference of object'), + 'entity'=>array('type'=>'integer','label'=>'Entity','index'=>true), + 'status'=>array('type'=>'integer','label'=>'Status','index'=>true), + 'date'=>array('type'=>'date','label'=>'Date','default'=>'__NOW__'), + 'title'=>array('type'=>'string','label'=>'Title'), + ); + /* END PROPERTY FIELDS - Do not remove this comment */ diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php index 28624dc9fc2..7e67c04ecc2 100644 --- a/htdocs/modulebuilder/template/myobject_list.php +++ b/htdocs/modulebuilder/template/myobject_list.php @@ -68,13 +68,7 @@ $toselect = GETPOST('toselect', 'array'); $id = GETPOST('id','int'); $backtopage = GETPOST('backtopage'); -$myparam = GETPOST('myparam','alpha'); - -$search_all=trim(GETPOST("sall")); -$search_field1=GETPOST("search_field1"); -$search_field2=GETPOST("search_field2"); -$search_myfield=GETPOST('search_myfield'); -$optioncss = GETPOST('optioncss','alpha'); +$optioncss = GETPOST('optioncss','alpha'); // Load variable for pagination $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; @@ -85,6 +79,7 @@ if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; + if (! $sortfield) $sortfield="t.rowid"; // Set here default search field if (! $sortorder) $sortorder="ASC"; @@ -96,6 +91,19 @@ if ($user->societe_id > 0) //accessforbidden(); } +// Initialize array of search criterias +$object=new MyModule($db); +$search_all=trim(GETPOST("search_all")); +$search=array(); +foreach($object->fields as $key) +{ + if (GETPOST('search_'.$key,'alpha')) $search[$key]=GETPOST('search_'.$key,'alpha'); +} +/*$search_field1=GETPOST("search_field1"); +$search_field2=GETPOST("search_field2"); +$search_myfield=GETPOST('search_myfield'); +*/ + // Initialize technical object to manage context to save list fields $contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'myobjectlist'; @@ -133,8 +141,6 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab } -$object=new Skeleton_Class($db); - From b016b1ca5f46549a3748c670e2c2bdc999d6a56c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 11 Jul 2017 23:19:47 +0200 Subject: [PATCH 16/22] Fix typo --- htdocs/langs/en_US/accountancy.lang | 2 +- htdocs/langs/en_US/main.lang | 3 ++- htdocs/modulebuilder/template/myobject_list.php | 12 ++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index 859fe1cca12..a4e7d72bc2c 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -103,7 +103,7 @@ LineOfExpenseReport=Line of expense report NoAccountSelected=No accounting account selected VentilatedinAccount=Binded successfully to the accounting account NotVentilatedinAccount=Not bound to the accounting account -XLineSuccessfullyBinded=%s products/services successfuly bound to an accounting account +XLineSuccessfullyBinded=%s products/services successfully bound to an accounting account XLineFailedToBeBinded=%s products/services were not bound to any accounting account ACCOUNTING_LIMIT_LIST_VENTILATION=Number of elements to bind shown by page (maximum recommended : 50) diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 58028423a35..a58d177061a 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -75,7 +75,8 @@ FileRenamed=The file was successfully renamed FileGenerated=The file was successfully generated FileSaved=The file was successfully saved FileUploaded=The file was successfully uploaded -FileTransferComplete=File(s) was uploaded successfuly +FileTransferComplete=File(s) was uploaded successfully +FilesDeleted=File(s) successfully deleted FileWasNotUploaded=A file is selected for attachment but was not yet uploaded. Click on "Attach file" for this. NbOfEntries=Nb of entries GoToWikiHelpPage=Read online help (Internet access needed) diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php index 7e67c04ecc2..1d7fad81473 100644 --- a/htdocs/modulebuilder/template/myobject_list.php +++ b/htdocs/modulebuilder/template/myobject_list.php @@ -174,11 +174,11 @@ if (empty($reshook)) } // Mass actions - $objectclass='Skeleton'; - $objectlabel='Skeleton'; - $permtoread = $user->rights->skeleton->read; - $permtodelete = $user->rights->skeleton->delete; - $uploaddir = $conf->skeleton->dir_output; + $objectclass='MyModule'; + $objectlabel='MyModule'; + $permtoread = $user->rights->mymodule->read; + $permtodelete = $user->rights->mymodule->delete; + $uploaddir = $conf->mymodule->dir_output; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; } @@ -290,7 +290,7 @@ if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&con if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; if ($search_field1 != '') $param.= '&search_field1='.urlencode($search_field1); if ($search_field2 != '') $param.= '&search_field2='.urlencode($search_field2); -if ($optioncss != '') $param.='&optioncss='.$optioncss; +if ($optioncss != '') $param.='&optioncss='.$optioncss; // Add $param from extra fields foreach ($search_array_options as $key => $val) { From 11cc1f04c4c129a30784b06c2dff69ef48bb3c9b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 12 Jul 2017 01:55:07 +0200 Subject: [PATCH 17/22] Work on modulebuilder --- htdocs/core/lib/modulebuilder.lib.php | 93 +++++++++++++++ htdocs/langs/en_US/main.lang | 1 + htdocs/langs/en_US/modulebuilder.lang | 9 +- htdocs/modulebuilder/index.php | 112 ++++++++++++------ .../template/class/myobject.class.php | 17 +-- .../modulebuilder/template/myobject_list.php | 94 +++++++-------- .../template/sql/llx_myobject.key.sql | 7 +- .../template/sql/llx_myobject.sql | 11 +- 8 files changed, 240 insertions(+), 104 deletions(-) create mode 100644 htdocs/core/lib/modulebuilder.lib.php diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php new file mode 100644 index 00000000000..f5f37ae91b1 --- /dev/null +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -0,0 +1,93 @@ + + * + * 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 htdocs/core/lib/memory.lib.php + * \brief Set of function for memory/cache management + */ + + +/** + * Save data into a memory area shared by all users, all sessions on server + * + * @param string $destdir Directory + * @param string $module Module name + * @param string $objectname Name of object + * @param string $newmask New mask + * @return int <0 if KO, >0 if OK + */ +function rebuildobjectsql($destdir, $module, $objectname, $newmask) +{ + global $db; + + if (empty($objectname)) return -1; + + dol_include_once(strtolower($module).'/class/'.strtolower($objectname).'.class.php'); + $object=new $objectname($db); + + // Edit sql files + $pathoffiletoedit=dol_osencode($destdir.'/sql/llx_'.strtolower($objectname).'.sql'); + + $contentsql = file_get_contents($pathoffiletoedit, 'r'); + + $i=0; + $texttoinsert = '-- BEGIN MODULEBUILDER FIELDS'."\n"; + foreach($object->fields as $key => $val) + { + $i++; + $texttoinsert.= "\t".$key." ".$val['type']; + if ($key == 'rowid') $texttoinsert.= ' AUTO_INCREMENT PRIMARY KEY'; + if ($key == 'entity') $texttoinsert.= ' DEFAULT 1'; + $texttoinsert.= ($val['notnull']?' NOT NULL':''); + if ($i < count($object->fields)) $texttoinsert.=", "; + $texttoinsert.= "\n"; + } + $texttoinsert.= "\t".'-- END MODULEBUILDER FIELDS'; + + $contentsql = preg_replace('/-- BEGIN MODULEBUILDER FIELDS.*END MODULEBUILDER FIELDS/ims', $texttoinsert, $contentsql); + + file_put_contents($pathoffiletoedit, $contentsql); + @chmod($pathoffiletoedit, octdec($newmask)); + + + + // Edit sql files + $pathoffiletoedit=dol_osencode($destdir.'/sql/llx_'.strtolower($objectname).'.key.sql'); + + $contentsql = file_get_contents($pathoffiletoedit, 'r'); + + $i=0; + $texttoinsert = '-- BEGIN MODULEBUILDER INDEXES'."\n"; + foreach($object->fields as $key => $val) + { + $i++; + if ($val['index']) + { + $texttoinsert.= "ALTER TABLE llx_".strtolower($objectname)." ADD INDEX idx_".strtolower($objectname)."_".$key." (".$key.");"; + $texttoinsert.= "\n"; + } + } + $texttoinsert.= '-- END MODULEBUILDER INDEXES'; + + $contentsql = preg_replace('/-- BEGIN MODULEBUILDER INDEXES.*END MODULEBUILDER INDEXES/ims', $texttoinsert, $contentsql); + + file_put_contents($pathoffiletoedit, $contentsql); + @chmod($pathoffiletoedit, octdec($newmask)); + + return 1; +} diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index a58d177061a..9251db5311f 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -736,6 +736,7 @@ ShowTransaction=Show entry on bank account GoIntoSetupToChangeLogo=Go into Home - Setup - Company to change logo or go into Home - Setup - Display to hide. Deny=Deny Denied=Denied +ListOf=List of %s ListOfTemplates=List of templates Gender=Gender Genderman=Man diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index 5a3470aebce..f73aa4a1eb8 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -9,7 +9,8 @@ NewObject=New object ModuleKey=Module key ObjectKey=Object key ModuleInitialized=Module initialized -FilesForObjectInitialized=Files for new object initialized +FilesForObjectInitialized=Files for new object '%s' initialized +FilesForObjectUpdated=Files for object '%s' updated ModuleBuilderDescdescription=Enter here all general information that describe your module ModuleBuilderDescspecifications=You can enter here a long text to describe the specifications of your module that is not already structured into other tabs. So you have on hand the rules to develop. Also this text content will be included into the generated documentation (see last tab). ModuleBuilderDescobjects=Define here the objects you want to manage with your module. A sql file, a page to list them, to create/edit/view a card and an API will be generated. @@ -39,4 +40,8 @@ PathToModuleDocumentation=Path to file of module/application documentation SpaceOrSpecialCharAreNotAllowed=Spaces or special characters are not allowed. FileNotYetGenerated=File not yet generated SpecificationFile=File with business rules -ConfirmDeleteProperty=Are you sure you want to delete the property %s ? This will change code in PHP class but also remove column from table definition of object. \ No newline at end of file +ConfirmDeleteProperty=Are you sure you want to delete the property %s ? This will change code in PHP class but also remove column from table definition of object. +NotNull=Not NULL +SearchAll=Used for 'search all' +DatabaseIndex=Database index +FileAlreadyExists=File %s already exists \ No newline at end of file diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index a1c30b7c94a..18d66187f16 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -24,6 +24,7 @@ if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION','1'); require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/modulebuilder.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $langs->load("admin"); @@ -58,6 +59,12 @@ $dirins = $tmp[0]; $FILEFLAG='modulebuilder.txt'; $now=dol_now(); +$newmask = 0; +if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; +if (empty($newmask)) // This should no happen +{ + $newmask='0664'; +} /* @@ -158,14 +165,6 @@ if ($dirins && $action == 'initobject' && $module && $objectname) $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template'; $destdir = $dirins.'/'.strtolower($module); - $arrayreplacement=array( - 'mymodule'=>strtolower($module), - 'MyModule'=>$module, - 'myobject'=>strtolower($objectname), - 'MyObject'=>$objectname - ); - - // Delete some files $filetogenerate = array( 'myobject_card.php'=>strtolower($objectname).'_card.php', @@ -182,7 +181,7 @@ if ($dirins && $action == 'initobject' && $module && $objectname) foreach($filetogenerate as $srcfile => $destfile) { - $result = dol_copy($srcdir.'/'.$srcfile, $destdir.'/'.$destfile); + $result = dol_copy($srcdir.'/'.$srcfile, $destdir.'/'.$destfile, $newmask, 0); if ($result <= 0) { if ($result < 0) @@ -193,7 +192,7 @@ if ($dirins && $action == 'initobject' && $module && $objectname) } else // $result == 0 { - setEventMessages($langs->trans("FileAlreadyExists", $srcdir.'/'.$srcfile, $destdir.'/'.$destfile), null, 'warnings'); + setEventMessages($langs->trans("FileAlreadyExists", $destfile), null, 'warnings'); } } else @@ -212,10 +211,10 @@ if ($dirins && $action == 'initobject' && $module && $objectname) //var_dump($phpfileval['fullname']); $arrayreplacement=array( - 'mymodule'=>strtolower($modulename), - 'MyModule'=>$modulename, - 'MYMODULE'=>strtoupper($modulename), - 'My module'=>$modulename, + 'mymodule'=>strtolower($module), + 'MyModule'=>$module, + 'MYMODULE'=>strtoupper($module), + 'My module'=>$module, 'htdocs/modulebuilder/template/'=>'', 'myobject'=>strtolower($objectname), 'MyObject'=>$objectname @@ -232,7 +231,32 @@ if ($dirins && $action == 'initobject' && $module && $objectname) if (! $error) { - setEventMessages('FilesForObjectInitialized', null); + // Edit sql with new properties + rebuildobjectsql($destdir, $module, $objectname, $newmask); + + // Edit the class file to write properties + + + } + + if (! $error) + { + setEventMessages($langs->trans('FilesForObjectInitialized', $objectname), null); + } +} + +if ($dirins && $action == 'addproperty' && !empty($module) && ! empty($tabobj)) +{ + $objectname = $tabobj; + + $destdir = $dirins.'/'.strtolower($module); + + // Edit sql with new properties + rebuildobjectsql($destdir, $module, $objectname, $newmask); + + if (! $error) + { + setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null); } } @@ -426,15 +450,7 @@ if ($action == 'savefile' && empty($cancel)) $content = GETPOST('editfilecontent'); // Save file on disk - $newmask = 0; - file_put_contents($pathoffile, $content); - if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; - if (empty($newmask)) // This should no happen - { - $newmask='0664'; - } - @chmod($pathoffile, octdec($newmask)); setEventMessages($langs->trans("FileSaved"), null); @@ -939,18 +955,22 @@ elseif (! empty($module)) $pathtoapi = strtolower($module).'/class/api_'.strtolower($tabobj).'.class.php'; $pathtolist = strtolower($module).'/'.strtolower($tabobj).'_list.php'; $pathtocard = strtolower($module).'/'.strtolower($tabobj).'_card.php'; + print '
'; print ' '.$langs->trans("ClassFile").' : '.$pathtoclass.''; print ' '.img_picto($langs->trans("Edit"), 'edit').''; print '
'; print ' '.$langs->trans("ApiClassFile").' : '.$pathtoapi.''; print ' '.img_picto($langs->trans("Edit"), 'edit').''; - print '
'; + print '
'; + print '
'; print ' '.$langs->trans("PageForList").' : '.$pathtolist.''; print ' '.img_picto($langs->trans("Edit"), 'edit').''; print '
'; print ' '.$langs->trans("PageForCreateEditView").' : '.$pathtocard.''; print ' '.img_picto($langs->trans("Edit"), 'edit').''; - print '
'; + print '
'; + + print '


'; $result = dol_include_once($pathtoclass); $tmpobjet = new $tabobj($db); @@ -964,7 +984,7 @@ elseif (! empty($module)) print '
'; print ''; - print ''; + print ''; print ''; print ''; print ''; @@ -974,11 +994,15 @@ elseif (! empty($module)) print '
'.$langs->trans("Property"); print ' ('.$langs->trans("Example").')'; print ''.$langs->trans("Label").''; + print $form->textwithpicto($langs->trans("Label"), $langs->trans("YouCanUseTranslationKey")); + print ''.$langs->trans("Type").''.$langs->trans("Position").''.$langs->trans("DefaultValue").''.$langs->trans("Index").''.$langs->trans("Position").''.$langs->trans("NotNull").''.$langs->trans("SearchAll").''.$langs->trans("DefaultValue").''.$langs->trans("DatabaseIndex").''.$langs->trans("Comment").'
'; print ''; @@ -1016,7 +1042,9 @@ elseif (! empty($module)) $proplabel=$propval['label']; $proptype=$propval['type']; $propposition=$propval['position']; - $propdefault=$propval['default']; + $propnotnull=$propval['notnull']; + $propsearchall=$propval['searchall']; + //$propdefault=$propval['default']; $propindex=$propval['index']; $propcomment=$propval['comment']; @@ -1031,14 +1059,20 @@ elseif (! empty($module)) print ''; print $proptype; print ''; + print ''; print $propposition; print ''; - print $propdefault; + print ''; + print $propnotnull?'X':''; print ''; - print yn($propindex); + print ''; + print $propsearchall?'X':''; + print ''; + print $propdefault; + print ''; + print $propindex?'X':''; print ''; print $propcomment; diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index 4c85a6e5a86..7b0d83dfff0 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -47,7 +47,7 @@ class MyObject extends CommonObject /** * @var array Does this field is linked to a thirdparty ? */ - protected $isnolinkedbythird=1; + protected $isnolinkedbythird = 1; /** * @var array Does myobject support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe */ @@ -58,18 +58,19 @@ class MyObject extends CommonObject public $picto = 'myobject'; - /* BEGIN PROPERTY FIELDS - Do not remove this comment */ + // BEGIN MODULEBUILDER PROPERTIES - Do not remove this comment /** * @var array Array with all fields and their property */ public $fields=array( - 'ref'=>array('type'=>'string','label'=>'Ref','position'=>10,'index'=>true,'comment'=>'Reference of object'), - 'entity'=>array('type'=>'integer','label'=>'Entity','index'=>true), - 'status'=>array('type'=>'integer','label'=>'Status','index'=>true), - 'date'=>array('type'=>'date','label'=>'Date','default'=>'__NOW__'), - 'title'=>array('type'=>'string','label'=>'Title'), + 'ref' =>array('type'=>'varchar(64)', 'label'=>'Ref', 'position'=>10, 'notnull'=>true, 'index'=>true, 'searchall'=>1, 'comment'=>'Reference of object'), + 'entity'=>array('type'=>'integer', 'label'=>'Entity', 'notnull'=>true, 'index'=>true), + 'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'searchall'=>1), + 'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'notnull'=>true, 'position'=>500), + 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'notnull'=>true, 'position'=>500), + 'status'=>array('type'=>'integer', 'label'=>'Status', 'index'=>true, 'position'=>1000), ); - /* END PROPERTY FIELDS - Do not remove this comment */ + // Do not remove this comment - END MODULEBUILDER PROPERTIES diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php index 1d7fad81473..72fec670cb1 100644 --- a/htdocs/modulebuilder/template/myobject_list.php +++ b/htdocs/modulebuilder/template/myobject_list.php @@ -65,6 +65,7 @@ $massaction = GETPOST('massaction','alpha'); $show_files = GETPOST('show_files','int'); $confirm = GETPOST('confirm','alpha'); $toselect = GETPOST('toselect', 'array'); +$contextpage= GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'myobjectlist'; // To manage different context of search $id = GETPOST('id','int'); $backtopage = GETPOST('backtopage'); @@ -80,32 +81,27 @@ $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (! $sortfield) $sortfield="t.rowid"; // Set here default search field +$object=new MyObject($db); + +// Default sort order (if not yet defined by previous GETPOST) +if (! $sortfield) $sortfield="t.".key($object->fields); // Set here default search field. By default 1st field in definition. if (! $sortorder) $sortorder="ASC"; // Protection if external user $socid=0; if ($user->societe_id > 0) { - $socid = $user->societe_id; - //accessforbidden(); + //$socid = $user->societe_id; + accessforbidden(); } // Initialize array of search criterias -$object=new MyModule($db); -$search_all=trim(GETPOST("search_all")); +$search_all=trim(GETPOST("search_all",'alpha')); $search=array(); -foreach($object->fields as $key) +foreach($object->fields as $key => $val) { if (GETPOST('search_'.$key,'alpha')) $search[$key]=GETPOST('search_'.$key,'alpha'); } -/*$search_field1=GETPOST("search_field1"); -$search_field2=GETPOST("search_field2"); -$search_myfield=GETPOST('search_myfield'); -*/ - -// Initialize technical object to manage context to save list fields -$contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'myobjectlist'; // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array $hookmanager->initHooks(array('myobjectlist')); @@ -116,21 +112,18 @@ $extralabels = $extrafields->fetch_name_optionals_label('myobject'); $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_'); // List of fields to search into when doing a "search in all" -$fieldstosearchall = array( - 't.ref'=>'Ref', - 't.note_public'=>'NotePublic', -); -if (empty($user->socid)) $fieldstosearchall["t.note_private"]="NotePrivate"; +$fieldstosearchall = array(); +foreach($object->fields as $key => $val) +{ + if ($val['searchall']) $fieldstosearchall['t.'.$key]=$val['label']; +} // Definition of fields for list -$arrayfields=array( - 't.field1'=>array('label'=>"Field1", 'checked'=>1), - 't.field2'=>array('label'=>"Field2", 'checked'=>1), - //'t.entity'=>array('label'=>"Entity", 'checked'=>1, 'enabled'=>(! empty($conf->multicompany->enabled) && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))), - 't.datec'=>array('label'=>"DateCreationShort", 'checked'=>0, 'position'=>500), - 't.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500), - //'t.statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000), -); +$arrayfields=array(); +foreach($object->fields as $key => $val) +{ + $arrayfields['t.'.$key]=array('label'=>$val['label'], 'checked'=>1); +} // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { @@ -143,11 +136,10 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab - /* * ACTIONS * - * Put here all code to do according to value of "action" parameter + * Put here all code to do according to value of "$action" parameter */ if (GETPOST('cancel')) { $action='list'; $massaction=''; } @@ -165,17 +157,17 @@ if (empty($reshook)) // Purge search criteria if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") ||GETPOST("button_removefilter")) // All tests are required to be compatible with all browsers { - $search_field1=''; - $search_field2=''; - $search_date_creation=''; - $search_date_update=''; + foreach($object->fields as $key => $val) + { + $search[$key]=''; + } $toselect=''; $search_array_options=array(); } // Mass actions - $objectclass='MyModule'; - $objectlabel='MyModule'; + $objectclass='MyObject'; + $objectlabel='MyObject'; $permtoread = $user->rights->mymodule->read; $permtodelete = $user->rights->mymodule->delete; $uploaddir = $conf->mymodule->dir_output; @@ -196,7 +188,7 @@ $form=new Form($db); //$help_url="EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes"; $help_url=''; -$title = $langs->trans('MyModuleListTitle'); +$title = $langs->trans('ListOf', $langs->transnoentitiesnoconv("MyObjects")); // Put here content of your page @@ -215,24 +207,26 @@ jQuery(document).ready(function() { }); '; - -$sql = "SELECT"; -$sql.= " t.rowid,"; -$sql.= " t.field1,"; -$sql.= " t.field2"; +$sql = 'SELECT '; +foreach($object->fields as $key => $val) +{ + $sql.='t.'.$key.', '; +} // Add fields from extrafields -foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : ''); +foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); // Add fields from hooks $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook $sql.=$hookmanager->resPrint; -$sql.= " FROM ".MAIN_DB_PREFIX."mytable as t"; -if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."mytable_extrafields as ef on (t.rowid = ef.fk_object)"; -$sql.= " WHERE 1 = 1"; -//$sql.= " WHERE u.entity IN (".getEntity('mytable').")"; -if ($search_field1) $sql.= natural_search("field1",$search_field1); -if ($search_field2) $sql.= natural_search("field2",$search_field2); -if ($sall) $sql.= natural_search(array_keys($fieldstosearchall), $sall); +$sql=preg_replace('/, $/','', $sql); +$sql.= " FROM ".MAIN_DB_PREFIX."myobject as t"; +if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."myobject_extrafields as ef on (t.rowid = ef.fk_object)"; +$sql.= " WHERE t.entity IN (".getEntity('myobject').")"; +foreach($search as $key => $val) +{ + if ($search[$key] != '') $sql.=natural_search($key, $search[$key], (($key == 'status')?2:($object->fields[$key]['type'] == 'integer'?1:0))); +} +if ($search_all) $sql.= natural_search(array_keys($fieldstosearchall), $search_all); // Add where from extra fields foreach ($search_array_options as $key => $val) { @@ -394,7 +388,7 @@ if (! empty($arrayfields['t.tms']['checked'])) print ''; print ''; @@ -507,7 +501,7 @@ while ($i < min($num, $limit)) } // Status /* - if (! empty($arrayfields['u.statut']['checked'])) + if (! empty($arrayfields['t.statut']['checked'])) { $userstatic->statut=$obj->statut; print ''.$userstatic->getLibStatut(3).'
'; -// LIST_OF_TD_TITLE_SEARCH -//if (! empty($arrayfields['t.field1']['checked'])) print ''; -//if (! empty($arrayfields['t.field2']['checked'])) print ''; +foreach($object->fields as $key => $val) +{ + if (in_array($key, array('datec','tms','status'))) continue; + $align=''; + if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; + if (in_array($val['type'], array('timestamp'))) $align.=' nowrap'; + if (! empty($arrayfields['t.'.$key]['checked'])) print ''; +} // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { @@ -376,25 +389,15 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab $parameters=array('arrayfields'=>$arrayfields); $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; -if (! empty($arrayfields['t.datec']['checked'])) +// Rest of fields search +foreach($object->fields as $key => $val) { - // Date creation - print ''; + if (! in_array($key, array('datec','tms','status'))) continue; + $align=''; + if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; + if (in_array($val['type'], array('timestamp'))) $align.=' nowrap'; + if (! empty($arrayfields['t.'.$key]['checked'])) print ''; } -if (! empty($arrayfields['t.tms']['checked'])) -{ - // Date modification - print ''; -} -/*if (! empty($arrayfields['t.statut']['checked'])) - { - // Status - print ''; - }*/ // Action column print ''; print ''."\n"; -// Fields title + +// Fields title label +// -------------------------------------------------------------------- print ''; -// LIST_OF_TD_TITLE_FIELDS -//if (! empty($arrayfields['t.field1']['checked'])) print_liste_field_titre($arrayfields['t.field1']['label'],$_SERVER['PHP_SELF'],'t.field1','',$param,'',$sortfield,$sortorder); -//if (! empty($arrayfields['t.field2']['checked'])) print_liste_field_titre($arrayfields['t.field2']['label'],$_SERVER['PHP_SELF'],'t.field2','',$param,'',$sortfield,$sortorder); +foreach($object->fields as $key => $val) +{ + if (in_array($key, array('datec','tms','status'))) continue; + $align=''; + if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; + if (in_array($val['type'], array('timestamp'))) $align.='nowrap'; + if (! empty($arrayfields['t.'.$key]['checked'])) print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align?'class="'.$align.'"':''), $sortfield, $sortorder, $align.' ')."\n"; +} // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { @@ -417,7 +427,7 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab $align=$extrafields->getAlignFlag($key); $sortonfield = "ef.".$key; if (! empty($extrafields->attribute_computed[$key])) $sortonfield=''; - print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder); + print getTitleFieldOfList($langs->trans($extralabels[$key]), 0, $_SERVER["PHP_SELF"], $sortonfield, "", $param, ($align?'align="'.$align.'"':''), $sortfield, $sortorder)."\n"; } } } @@ -425,10 +435,16 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab $parameters=array('arrayfields'=>$arrayfields); $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; -if (! empty($arrayfields['t.datec']['checked'])) print_liste_field_titre($arrayfields['t.datec']['label'],$_SERVER["PHP_SELF"],"t.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder); -if (! empty($arrayfields['t.tms']['checked'])) print_liste_field_titre($arrayfields['t.tms']['label'],$_SERVER["PHP_SELF"],"t.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder); -//if (! empty($arrayfields['t.status']['checked'])) print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"t.status","",$param,'align="center"',$sortfield,$sortorder); -print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch '); +// Rest of fields title +foreach($object->fields as $key => $val) +{ + if (! in_array($key, array('datec','tms','status'))) continue; + $align=''; + if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; + if (in_array($val['type'], array('timestamp'))) $align.=' nowrap'; + if (! empty($arrayfields['t.'.$key]['checked'])) print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align?'class="'.$align.'"':''), $sortfield, $sortorder, $align.' ')."\n"; +} +print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ')."\n"; print ''."\n"; @@ -440,6 +456,8 @@ foreach ($extrafields->attribute_computed as $key => $val) } +// Loop on record +// -------------------------------------------------------------------- $i=0; $totalarray=array(); while ($i < min($num, $limit)) @@ -449,18 +467,22 @@ while ($i < min($num, $limit)) { // Show here line of result print ''; - // LIST_OF_TD_FIELDS_LIST - /* - if (! empty($arrayfields['t.field1']['checked'])) + foreach($object->fields as $key => $val) { - print ''; - if (! $i) $totalarray['nbfield']++; + if (in_array($key, array('datec','tms','status'))) continue; + $align=''; + if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; + if (in_array($val['type'], array('timestamp'))) $align.='nowrap'; + if (! empty($arrayfields['t.'.$key]['checked'])) + { + print ''; + if (in_array($val['type'], array('date','datetime','timestamp'))) print dol_print_date($db->jdate($obj->$key), 'dayhour'); + elseif ($key == 'status') print ''; + else print $obj->$key; + print ''; + if (! $i) $totalarray['nbfield']++; + } } - if (! empty($arrayfields['t.field2']['checked'])) - { - print ''; - if (! $i) $totalarray['nbfield']++; - }*/ // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { @@ -483,30 +505,23 @@ while ($i < min($num, $limit)) $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj); $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - // Date creation - if (! empty($arrayfields['t.datec']['checked'])) + // Rest of fields + foreach($object->fields as $key => $val) { - print ''; - if (! $i) $totalarray['nbfield']++; + if (! in_array($key, array('datec','tms','status'))) continue; + $align=''; + if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; + if (in_array($val['type'], array('timestamp'))) $align.='nowrap'; + if (! empty($arrayfields['t.'.$key]['checked'])) + { + print ''; + if (in_array($val['type'], array('date','datetime','timestamp'))) print dol_print_date($db->jdate($obj->$key), 'dayhour'); + elseif ($key == 'status') print ''; + else print $obj->$key; + print ''; + if (! $i) $totalarray['nbfield']++; + } } - // Date modification - if (! empty($arrayfields['t.tms']['checked'])) - { - print ''; - if (! $i) $totalarray['nbfield']++; - } - // Status - /* - if (! empty($arrayfields['t.statut']['checked'])) - { - $userstatic->statut=$obj->statut; - print ''; - }*/ - // Action column print ''; else print ''; } - elseif ($totalarray['totalhtfield'] == $i) print ''; + elseif ($totalarray['totalhtfield'] == $i) print ''; elseif ($totalarray['totalvatfield'] == $i) print ''; elseif ($totalarray['totalttcfield'] == $i) print ''; else print ''; @@ -567,13 +582,16 @@ print ''."\n"; if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) { + require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'); + $formfile = new FormFile($db); + // Show list of available documents $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; $urlsource.=str_replace('&','&',$param); $filedir=$diroutputmassaction; - $genallowed=$user->rights->facture->lire; - $delallowed=$user->rights->facture->lire; + $genallowed=$user->rights->mymodule->read; + $delallowed=$user->rights->mymodule->read; print $formfile->showdocuments('massfilesarea_mymodule','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,''); } From 33ceb22b8b814aca7a43616bb801f29692bf0f98 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 12 Jul 2017 13:25:18 +0200 Subject: [PATCH 19/22] Fix error management into modulebuilder --- htdocs/core/class/commonobject.class.php | 357 +++++++++++------ htdocs/core/lib/modulebuilder.lib.php | 114 +++--- htdocs/langs/en_US/main.lang | 1 + .../template/class/myobject.class.php | 364 +----------------- .../modulebuilder/template/myobject_card.php | 84 ++-- .../modulebuilder/template/myobject_list.php | 46 +-- 6 files changed, 372 insertions(+), 594 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 96de26be956..7917234158e 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -599,7 +599,7 @@ abstract class CommonObject } $datecreate = dol_now(); - + // Socpeople must have already been added by some a trigger, then we have to check it to avoid DB_ERROR_RECORD_ALREADY_EXISTS error $TListeContacts=$this->liste_contact(-1, $source); $already_added=false; @@ -611,11 +611,11 @@ abstract class CommonObject } } } - + if(!$already_added) { - + $this->db->begin(); - + // Insertion dans la base $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; @@ -623,7 +623,7 @@ abstract class CommonObject $sql.= "'".$this->db->idate($datecreate)."'"; $sql.= ", 4, ". $id_type_contact; $sql.= ")"; - + $resql=$this->db->query($sql); if ($resql) { @@ -636,7 +636,7 @@ abstract class CommonObject return -1; } } - + $this->db->commit(); return 1; } @@ -4726,6 +4726,9 @@ abstract class CommonObject return $buyPrice; } + + + /** * Function test if type is date * @@ -4734,7 +4737,7 @@ abstract class CommonObject */ protected function isDate($info) { - if(isset($info['type']) && $info['type']=='date') return true; + if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) return true; else return false; } @@ -4880,40 +4883,6 @@ abstract class CommonObject return $query; } - /** - * Create object into database - * - * @param User $user User that creates - * @param bool $notrigger false=launch triggers after, true=disable triggers - * - * @return int <0 if KO, Id of created object if OK - */ - public function createCommon(User $user, $notrigger = false) - { - - $fields = array_merge(array('datec'=>$this->db->idate(dol_now())), $this->set_save_query()); - - foreach ($fields as $k => $v) { - - $keys[] = $k; - $values[] = $this->quote($v); - - } - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.' - ( '.implode( ",", $keys ).' ) - VALUES ( '.implode( ",", $values ).' ) '; - $res = $this->db->query( $sql ); - if($res===false) { - - return false; - } - - // TODO Add triggers - - return true; - - } - /** * Function to load data into current object this * @@ -4921,39 +4890,39 @@ abstract class CommonObject */ private function set_vars_by_db(&$obj) { - foreach ($this->fields as $field => $info) - { - if($this->isDate($info)) - { - if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0; - else $this->{$field} = strtotime($obj->{$field}); - } - elseif($this->isArray($info)) - { - $this->{$field} = @unserialize($obj->{$field}); - // Hack for data not in UTF8 - if($this->{$field } === FALSE) @unserialize(utf8_decode($obj->{$field})); - } - elseif($this->isInt($info)) - { - $this->{$field} = (int) $obj->{$field}; - } - elseif($this->isFloat($info)) - { - $this->{$field} = (double) $obj->{$field}; - } - elseif($this->isNull($info)) - { - $val = $obj->{$field}; - // zero is not null - $this->{$field} = (is_null($val) || (empty($val) && $val!==0 && $val!=='0') ? null : $val); - } - else - { - $this->{$field} = $obj->{$field}; - } + foreach ($this->fields as $field => $info) + { + if($this->isDate($info)) + { + if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0; + else $this->{$field} = strtotime($obj->{$field}); + } + elseif($this->isArray($info)) + { + $this->{$field} = @unserialize($obj->{$field}); + // Hack for data not in UTF8 + if($this->{$field } === FALSE) @unserialize(utf8_decode($obj->{$field})); + } + elseif($this->isInt($info)) + { + $this->{$field} = (int) $obj->{$field}; + } + elseif($this->isFloat($info)) + { + $this->{$field} = (double) $obj->{$field}; + } + elseif($this->isNull($info)) + { + $val = $obj->{$field}; + // zero is not null + $this->{$field} = (is_null($val) || (empty($val) && $val!==0 && $val!=='0') ? null : $val); + } + else + { + $this->{$field} = $obj->{$field}; + } - } + } } /** @@ -4963,21 +4932,134 @@ abstract class CommonObject */ private function get_field_list() { - $keys = array_keys($this->fields); - return implode(',', $keys); + $keys = array_keys($this->fields); + return implode(',', $keys); + } + + /** + * Add quote to field value if necessary + * + * @param string|int $value value to protect + * @return string|int + */ + protected function quote($value) { + + if(is_null($value)) return 'NULL'; + else if(is_numeric($value)) return $value; + else return "'".$this->db->escape( $value )."'"; + + } + + + /** + * Create object into database + * + * @param User $user User that creates + * @param bool $notrigger false=launch triggers after, true=disable triggers + * @return int <0 if KO, Id of created object if OK + */ + public function createCommon(User $user, $notrigger = false) + { + $error = 0; + + $fields = array_merge(array('datec'=>$this->db->idate(dol_now())), $this->set_save_query()); + + foreach ($fields as $k => $v) { + $keys[] = $k; + $values[] = $this->quote($v); + } + + $this->db->begin(); + + if (! $error) + { + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.' + ( '.implode( ",", $keys ).' ) + VALUES ( '.implode( ",", $values ).' ) '; + $res = $this->db->query( $sql ); + if ($res===false) { + $error++; + $this->errors[] = $this->db->lasterror(); + } + } + + if (! $error && ! $notrigger) { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); + + if (!$notrigger) { + // Call triggers + $result=$this->call_trigger(strtoupper(get_class(self)).'_CREATE',$user); + if ($result < 0) { $error++; } + // End call triggers + } + } + + // Commit or rollback + if ($error) { + $this->db->rollback(); + return -1; + } else { + $this->db->commit(); + return $this->id; + } + } + + /** + * Load an object from its id and create a new one in database + * + * @param User $user User that creates + * @param int $fromid Id of object to clone + * @return int New id of clone + */ + public function createFromCloneCommon(User $user, $fromid) + { + global $user; + + $error = 0; + + dol_syslog(__METHOD__, LOG_DEBUG); + + $object = new self($this->db); + + $this->db->begin(); + + // Load source object + $object->fetchCommon($fromid); + // Reset object + $object->id = 0; + + // Clear fields + // ... + + // Create clone + $result = $object->createCommon($user); + + // Other options + if ($result < 0) { + $error ++; + $this->errors = $object->errors; + dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); + } + + // End + if (!$error) { + $this->db->commit(); + return $object->id; + } else { + $this->db->rollback(); + return -1; + } } /** * Load object in memory from the database * - * @param int $id Id object - * @param string $ref Ref - * - * @return int <0 if KO, 0 if not found, >0 if OK + * @param int $id Id object + * @param string $ref Ref + * @return int <0 if KO, 0 if not found, >0 if OK */ public function fetchCommon($id, $ref = null) { - if (empty($id) && empty($ref)) return false; $sql = 'SELECT '.$this->get_field_list().', datec, tms'; @@ -4991,13 +5073,20 @@ abstract class CommonObject { if ($obj = $this->db->fetch_object($res)) { - $this->id = $id; - $this->set_vars_by_db($obj); + if ($obj) + { + $this->id = $id; + $this->set_vars_by_db($obj); - $this->datec = $this->db->idate($obj->datec); - $this->tms = $this->db->idate($obj->tms); + $this->datec = $this->db->idate($obj->datec); + $this->tms = $this->db->idate($obj->tms); - return $this->id; + return $this->id; + } + else + { + return 0; + } } else { @@ -5019,15 +5108,15 @@ abstract class CommonObject * * @param User $user User that modifies * @param bool $notrigger false=launch triggers after, true=disable triggers - * - * @return int <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK */ public function updateCommon(User $user, $notrigger = false) { + $error = 0; + $fields = $this->set_save_query(); foreach ($fields as $k => $v) { - if (is_array($key)){ $i=array_search($k, $key); if ( $i !== false) { @@ -5040,57 +5129,93 @@ abstract class CommonObject continue; } } - $tmp[] = $k.'='.$this->quote($v); } $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET '.implode( ',', $tmp ).' WHERE rowid='.$this->id ; - $res = $this->db->query( $sql ); - if($res===false) { - //error - return false; + $this->db->begin(); + + if (! $error) + { + $res = $this->db->query($sql); + if ($res===false) + { + $error++; + $this->errors[] = $this->db->lasterror(); + } } - // TODO Add triggers + if (! $error && ! $notrigger) { + // Call triggers + $result=$this->call_trigger(strtoupper(get_class(self)).'_MODIFY',$user); + if ($result < 0) { $error++; } //Do also here what you must do to rollback action if trigger fail + // End call triggers + } - return true; + // Commit or rollback + if ($error) { + $this->db->rollback(); + return -1; + } else { + $this->db->commit(); + return $this->id; + } } /** * Delete object in database * - * @param User $user User that deletes - * @param bool $notrigger false=launch triggers after, true=disable triggers - * - * @return int <0 if KO, >0 if OK + * @param User $user User that deletes + * @param bool $notrigger false=launch triggers after, true=disable triggers + * @return int <0 if KO, >0 if OK */ public function deleteCommon(User $user, $notrigger = false) { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.$this->id; + $error=0; - $res = $this->db->query( $sql ); - if($res===false) { - return false; + $this->db->begin(); + + if (! $error) { + if (! $notrigger) { + // Call triggers + $result=$this->call_trigger(strtoupper(get_class(self)).'_DELETE', $user); + if ($result < 0) { $error++; } // Do also here what you must do to rollback action if trigger fail + // End call triggers + } + } + + if (! $error) + { + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.$this->id; + + $res = $this->db->query($sql); + if($res===false) { + $error++; + $this->errors[] = $this->db->lasterror(); + } + } + + // Commit or rollback + if ($error) { + $this->db->rollback(); + return -1; + } else { + $this->db->commit(); + return 1; } - - // TODO Add triggers - - return true; } /** - * Add quote to field value if necessary + * Initialise object with example values + * Id must be 0 if object instance is a specimen * - * @param string|int $value value to protect - * @return string|int + * @return void */ - protected function quote($value) { - - if(is_null($value)) return 'NULL'; - else if(is_numeric($value)) return $value; - else return "'".$this->db->escape( $value )."'"; + public function initAsSpecimenCommon() + { + $this->id = 0; + // TODO... } } - diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index 7c14f139c59..cb5d143cff9 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -55,67 +55,69 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask) { include_once $pathoffiletoeditsrc; if (class_exists($objectname)) $object=new $objectname($db); + + // Backup old file + dol_copy($pathoffiletoeditsrc, $pathoffiletoeditsrc.'.back', $newmask, 1); + + // Edit class files + $contentclass = file_get_contents(dol_osencode($pathoffiletoeditsrc), 'r'); + + $i=0; + $texttoinsert = '// BEGIN MODULEBUILDER PROPERTIES'."\n"; + $texttoinsert.= "\t".'/**'."\n"; + $texttoinsert.= "\t".' * @var array Array with all fields and their property'."\n"; + $texttoinsert.= "\t".' */'."\n"; + $texttoinsert.= "\t".'public $fields=array('."\n"; + + if (count($object->fields)) + { + foreach($object->fields as $key => $val) + { + $i++; + $typephp=''; + $texttoinsert.= "\t\t'".$key."' => array('type'=>'".$val['type']."', 'label'=>'".$val['label']."',"; + if ($val['position']) $texttoinsert.= " 'position'=>".$val['position'].","; + if ($val['notnull']) $texttoinsert.= " 'notnull'=>".$val['notnull'].","; + if ($val['index']) $texttoinsert.= " 'index'=>".$val['index'].","; + if ($val['searchall']) $texttoinsert.= " 'searchall'=>".$val['searchall'].","; + if ($val['comment']) $texttoinsert.= " 'comment'=>'".$val['comment']."',"; + $texttoinsert.= "),\n"; + } + } + $texttoinsert.= "\t".');'."\n"; + + $texttoinsert.= "\n"; + + if (count($object->fields)) + { + foreach($object->fields as $key => $val) + { + $i++; + $typephp=''; + $texttoinsert.= "\t".'public $'.$key.$typephp.";"; + //if ($key == 'rowid') $texttoinsert.= ' AUTO_INCREMENT PRIMARY KEY'; + //if ($key == 'entity') $texttoinsert.= ' DEFAULT 1'; + //$texttoinsert.= ($val['notnull']?' NOT NULL':''); + //if ($i < count($object->fields)) $texttoinsert.=";"; + $texttoinsert.= "\n"; + } + } + + $texttoinsert.= "\t".'// END MODULEBUILDER PROPERTIES'; + + $contentclass = preg_replace('/\/\/ BEGIN MODULEBUILDER PROPERTIES.*END MODULEBUILDER PROPERTIES/ims', $texttoinsert, $contentclass); + + //file_put_contents($pathoffiletoedittmp, $contentclass); + file_put_contents(dol_osencode($pathoffiletoedittarget), $contentclass); + @chmod($pathoffiletoedit, octdec($newmask)); + + return 1; } catch(Exception $e) { print $e->getMessage(); + return -1; } - - // Edit class files - - $contentclass = file_get_contents(dol_osencode($pathoffiletoeditsrc), 'r'); - - $i=0; - $texttoinsert = '// BEGIN MODULEBUILDER PROPERTIES'."\n"; - $texttoinsert.= "\t".'/**'."\n"; - $texttoinsert.= "\t".' * @var array Array with all fields and their property'."\n"; - $texttoinsert.= "\t".' */'."\n"; - $texttoinsert.= "\t".'public $fields=array('."\n"; - - if (count($object->fields)) - { - foreach($object->fields as $key => $val) - { - $i++; - $typephp=''; - $texttoinsert.= "\t\t'".$key."' => array('type'=>'".$val['type']."', 'label'=>'".$val['label']."',"; - if ($val['position']) $texttoinsert.= " 'position'=>".$val['position'].","; - if ($val['notnull']) $texttoinsert.= " 'notnull'=>".$val['notnull'].","; - if ($val['index']) $texttoinsert.= " 'index'=>".$val['index'].","; - if ($val['searchall']) $texttoinsert.= " 'searchall'=>".$val['searchall'].","; - if ($val['comment']) $texttoinsert.= " 'comment'=>'".$val['comment']."',"; - $texttoinsert.= "),\n"; - } - } - $texttoinsert.= "\t".');'."\n"; - - $texttoinsert.= "\n"; - - if (count($object->fields)) - { - foreach($object->fields as $key => $val) - { - $i++; - $typephp=''; - $texttoinsert.= "\t".'public $'.$key.$typephp.";"; - //if ($key == 'rowid') $texttoinsert.= ' AUTO_INCREMENT PRIMARY KEY'; - //if ($key == 'entity') $texttoinsert.= ' DEFAULT 1'; - //$texttoinsert.= ($val['notnull']?' NOT NULL':''); - //if ($i < count($object->fields)) $texttoinsert.=";"; - $texttoinsert.= "\n"; - } - } - - $texttoinsert.= "\t".'// END MODULEBUILDER PROPERTIES'; - - $contentclass = preg_replace('/\/\/ BEGIN MODULEBUILDER PROPERTIES.*END MODULEBUILDER PROPERTIES/ims', $texttoinsert, $contentclass); - - //file_put_contents($pathoffiletoedittmp, $contentclass); - file_put_contents(dol_osencode($pathoffiletoedittarget), $contentclass); - @chmod($pathoffiletoedit, octdec($newmask)); - - - return 1; } /** diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 9251db5311f..88b9d2a3fb0 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -197,6 +197,7 @@ Parameter=Parameter Parameters=Parameters Value=Value PersonalValue=Personal value +NewObject=New %s NewValue=New value CurrentValue=Current value Code=Code diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index 6f55f2c9ef6..f8882b68c56 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -109,366 +109,6 @@ class MyObject extends CommonObject $this->db = $db; } - /** - * Create object into database - * - * @param User $user User that creates - * @param bool $notrigger false=launch triggers after, true=disable triggers - * - * @return int <0 if KO, Id of created object if OK - */ - public function create(User $user, $notrigger = false) - { - dol_syslog(__METHOD__, LOG_DEBUG); - - $error = 0; - - // Clean parameters - if (isset($this->prop1)) { - $this->prop1 = trim($this->prop1); - } - if (isset($this->prop2)) { - $this->prop2 = trim($this->prop2); - } - //... - - // Check parameters - // Put here code to add control on parameters values - - // Insert request - $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; - $sql .= ' field1,'; - $sql .= ' field2'; - //... - $sql .= ') VALUES ('; - $sql .= ' \'' . $this->prop1 . '\','; - $sql .= ' \'' . $this->prop2 . '\''; - //... - $sql .= ')'; - - $this->db->begin(); - - $resql = $this->db->query($sql); - if (!$resql) { - $error ++; - $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); - } - - if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); - - if (!$notrigger) { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action to call a trigger. - - //// Call triggers - //$result=$this->call_trigger('MYOBJECT_CREATE',$user); - //if ($result < 0) $error++; - //// End call triggers - } - } - - // Commit or rollback - if ($error) { - $this->db->rollback(); - - return - 1 * $error; - } else { - $this->db->commit(); - - return $this->id; - } - } - - /** - * Load object in memory from the database - * - * @param int $id Id object - * @param string $ref Ref - * @return int <0 if KO, 0 if not found, >0 if OK - */ - public function fetch($id, $ref = null) - { - dol_syslog(__METHOD__, LOG_DEBUG); - - $sql = 'SELECT'; - $sql .= ' t.rowid,'; - $sql .= ' t.field1,'; - $sql .= ' t.field2'; - //... - $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; - $sql.= ' WHERE 1 = 1'; - if (! empty($conf->multicompany->enabled)) { - $sql .= " AND entity IN (" . getEntity('mymoduleobject') . ")"; - } - if (null !== $ref) { - $sql .= ' AND t.ref = ' . '\'' . $ref . '\''; - } else { - $sql .= ' AND t.rowid = ' . $id; - } - - $resql = $this->db->query($sql); - if ($resql) { - $numrows = $this->db->num_rows($resql); - if ($numrows) { - $obj = $this->db->fetch_object($resql); - - $this->id = $obj->rowid; - $this->prop1 = $obj->field1; - $this->prop2 = $obj->field2; - //... - } - - $this->db->free($resql); - - $this->fetch_optionals(); - - // $this->fetch_lines(); - - if ($numrows) { - return 1; - } else { - return 0; - } - } else { - $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); - return - 1; - } - } - - /** - * Load object in memory from the database - * - * @param string $sortorder Sort Order - * @param string $sortfield Sort field - * @param int $limit offset limit - * @param int $offset offset limit - * @param array $filter filter array - * @param string $filtermode filter mode (AND or OR) - * - * @return int <0 if KO, >0 if OK - */ - public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND') - { - dol_syslog(__METHOD__, LOG_DEBUG); - - $sql = 'SELECT'; - $sql .= ' t.rowid,'; - $sql .= ' t.field1,'; - $sql .= ' t.field2'; - //... - $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t'; - - // Manage filter - $sqlwhere = array(); - if (count($filter) > 0) { - foreach ($filter as $key => $value) { - $sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; - } - } - $sql.= ' WHERE 1 = 1'; - if (! empty($conf->multicompany->enabled)) { - $sql .= " AND entity IN (" . getEntity('mymoduleobject') . ")"; - } - if (count($sqlwhere) > 0) { - $sql .= ' AND ' . implode(' '.$filtermode.' ', $sqlwhere); - } - if (!empty($sortfield)) { - $sql .= $this->db->order($sortfield,$sortorder); - } - if (!empty($limit)) { - $sql .= ' ' . $this->db->plimit($limit, $offset); - } - - $resql = $this->db->query($sql); - if ($resql) { - $num = $this->db->num_rows($resql); - - while ($obj = $this->db->fetch_object($resql)) { - $line = new self($this->db); - - $line->id = $obj->rowid; - $line->prop1 = $obj->field1; - $line->prop2 = $obj->field2; - //... - } - $this->db->free($resql); - - return $num; - } else { - $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); - - return - 1; - } - } - - /** - * Update object into database - * - * @param User $user User that modifies - * @param bool $notrigger false=launch triggers after, true=disable triggers - * - * @return int <0 if KO, >0 if OK - */ - public function update(User $user, $notrigger = false) - { - dol_syslog(__METHOD__, LOG_DEBUG); - - $error = 0; - - // Clean parameters - if (isset($this->prop1)) { - $this->prop1 = trim($this->prop1); - } - if (isset($this->prop2)) { - $this->prop2 = trim($this->prop2); - } - //... - - // Check parameters - // Put here code to add a control on parameters values - - // Update request - $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; - $sql .= " field1=".(isset($this->field1)?"'".$this->db->escape($this->field1)."'":"null").","; - $sql .= " field2=".(isset($this->field2)?"'".$this->db->escape($this->field2)."'":"null").""; - //... - $sql .= ' WHERE rowid=' . $this->id; - - $this->db->begin(); - - $resql = $this->db->query($sql); - if (!$resql) { - $error ++; - $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); - } - - if (!$error && !$notrigger) { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action calls a trigger. - - //// Call triggers - //$result=$this->call_trigger('MYOBJECT_MODIFY',$user); - //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} - //// End call triggers - } - - // Commit or rollback - if ($error) { - $this->db->rollback(); - - return - 1 * $error; - } else { - $this->db->commit(); - - return 1; - } - } - - /** - * Delete object in database - * - * @param User $user User that deletes - * @param bool $notrigger false=launch triggers after, true=disable triggers - * - * @return int <0 if KO, >0 if OK - */ - public function delete(User $user, $notrigger = false) - { - dol_syslog(__METHOD__, LOG_DEBUG); - - $error = 0; - - $this->db->begin(); - - if (!$error) { - if (!$notrigger) { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action calls a trigger. - - //// Call triggers - //$result=$this->call_trigger('MYOBJECT_DELETE',$user); - //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} - //// End call triggers - } - } - - // If you need to delete child tables to, you can insert them here - - if (!$error) { - $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element; - $sql .= ' WHERE rowid=' . $this->id; - - $resql = $this->db->query($sql); - if (!$resql) { - $error ++; - $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); - } - } - - // Commit or rollback - if ($error) { - $this->db->rollback(); - - return - 1 * $error; - } else { - $this->db->commit(); - - return 1; - } - } - - /** - * Load an object from its id and create a new one in database - * - * @param int $fromid Id of object to clone - * - * @return int New id of clone - */ - public function createFromClone($fromid) - { - dol_syslog(__METHOD__, LOG_DEBUG); - - global $user; - $error = 0; - $object = new self($this->db); - - $this->db->begin(); - - // Load source object - $object->fetch($fromid); - // Reset object - $object->id = 0; - - // Clear fields - // ... - - // Create clone - $result = $object->create($user); - - // Other options - if ($result < 0) { - $error ++; - $this->errors = $object->errors; - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); - } - - // End - if (!$error) { - $this->db->commit(); - - return $object->id; - } else { - $this->db->rollback(); - - return - 1; - } - } /** * Return a link to the object card (with optionaly the picto) @@ -592,9 +232,7 @@ class MyObject extends CommonObject */ public function initAsSpecimen() { - $this->id = 0; - $this->prop1 = 'prop1'; - $this->prop2 = 'prop2'; + $this->initAsSpecimenCommon(); } } diff --git a/htdocs/modulebuilder/template/myobject_card.php b/htdocs/modulebuilder/template/myobject_card.php index 73f00abc89f..14b88767128 100644 --- a/htdocs/modulebuilder/template/myobject_card.php +++ b/htdocs/modulebuilder/template/myobject_card.php @@ -58,14 +58,27 @@ dol_include_once('/mymodule/class/myobject.class.php'); $langs->loadLangs(array("mymodule","other")); // Get parameters -$id = GETPOST('id','int'); -$action = GETPOST('action','alpha'); -$cancel = GETPOST('cancel'); -$backtopage = GETPOST('backtopage'); -$myparam = GETPOST('myparam','alpha'); +$id = GETPOST('id', 'int'); +$action = GETPOST('action', 'alpha'); +$cancel = GETPOST('cancel', 'aZ09'); +$backtopage = GETPOST('backtopage', 'alpha'); -$search_field1=GETPOST("search_field1"); -$search_field2=GETPOST("search_field2"); +// Initialize technical objects +$object=new MyObject($db); +$extrafields = new ExtraFields($db); +$diroutputmassaction=$conf->mymodule->dir_output . '/temp/massgeneration/'.$user->id; +$hookmanager->initHooks(array('myobjectcard')); // Note that conf->hooks_modules contains array +// Fetch optionals attributes and labels +$extralabels = $extrafields->fetch_name_optionals_label('myobject'); +$search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_'); + +// Initialize array of search criterias +$search_all=trim(GETPOST("search_all",'alpha')); +$search=array(); +foreach($object->fields as $key => $val) +{ + if (GETPOST('search_'.$key,'alpha')) $search[$key]=GETPOST('search_'.$key,'alpha'); +} if (empty($action) && empty($id) && empty($ref)) $action='view'; @@ -76,19 +89,12 @@ if ($user->societe_id > 0) } //$result = restrictedArea($user, 'mymodule', $id); - -$object = new MyObject_Class($db); -$extrafields = new ExtraFields($db); - // fetch optionals attributes and labels $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); // Load object include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals -// Initialize technical object to manage hooks of modules. Note that conf->hooks_modules contains array array -$hookmanager->initHooks(array('mymodule')); - /* @@ -107,7 +113,7 @@ if (empty($reshook)) { if ($action != 'addlink') { - $urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/list.php',1); + $urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/myobject_list.php',1); header("Location: ".$urltogo); exit; } @@ -120,33 +126,35 @@ if (empty($reshook)) { if ($cancel) { - $urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/list.php',1); + $urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/myobject_list.php',1); header("Location: ".$urltogo); exit; } $error=0; - /* object_prop_getpost_prop */ - $object->prop1=GETPOST("field1"); - $object->prop2=GETPOST("field2"); - - if (empty($object->ref)) - { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")), null, 'errors'); - } + foreach ($object->fields as $key => $val) + { + $object->$key=GETPOST($key,'alpha'); + if (in_array($key, array('entity', 'datec', 'tms'))) continue; + if ($val['notnull'] && $object->$key == '') + { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv($val['label'])), null, 'errors'); + } + } if (! $error) { - $result=$object->create($user); + $result=$object->createCommon($user); if ($result > 0) { // Creation OK - $urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/list.php',1); + $urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/myobject_list.php',1); header("Location: ".$urltogo); exit; } + else { // Creation KO if (! empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); @@ -203,7 +211,7 @@ if (empty($reshook)) { // Delete OK setEventMessages("RecordDeleted", null, 'mesgs'); - header("Location: ".dol_buildpath('/mymodule/list.php',1)); + header("Location: ".dol_buildpath('/mymodule/myobject_list.php',1)); exit; } else @@ -225,10 +233,7 @@ if (empty($reshook)) $form=new Form($db); -llxHeader('','MyPageName',''); - - -// Put here content of your page +llxHeader('','MyObject',''); // Example : Adding jquery code print '
'; - print ''; - print ''; - print $form->selectarray('search_statut', array('-1'=>'','0'=>$langs->trans('Disabled'),'1'=>$langs->trans('Enabled')),$search_statut); - print ''; $searchpicto=$form->showFilterButtons(); @@ -402,11 +405,18 @@ print $searchpicto; print '
'.$obj->field1.''.$object->getLibStatut(3).''.$obj->field2.''; - print dol_print_date($db->jdate($obj->date_creation), 'dayhour'); - print ''.$object->getLibStatut(3).''; - print dol_print_date($db->jdate($obj->date_update), 'dayhour'); - print ''.$userstatic->getLibStatut(3).''; if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined @@ -536,7 +551,7 @@ if (isset($totalarray['totalhtfield'])) if ($num < $limit) print ''.$langs->trans("Total").''.$langs->trans("Totalforthispage").''.price($totalarray['totalht']).''.price($totalarray['totalht']).''.price($totalarray['totalvat']).''.price($totalarray['totalttc']).'