From d3ef78df479ae270f66df2f73b34d25721905607 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 24 Sep 2012 00:10:01 +0200 Subject: [PATCH] Qual: Respect database rules Qual: Add indexes --- htdocs/holiday/admin/holiday.php | 61 ++++++++----------- .../install/mysql/tables/llx_holiday.key.sql | 21 +++++++ htdocs/install/mysql/tables/llx_holiday.sql | 30 ++++----- .../mysql/tables/llx_holiday_config.sql | 20 +++++- .../mysql/tables/llx_holiday_events.key.sql | 19 ++++++ .../mysql/tables/llx_holiday_events.sql | 25 +++++++- .../install/mysql/tables/llx_holiday_logs.sql | 30 +++++++-- .../mysql/tables/llx_holiday_users.sql | 4 +- 8 files changed, 149 insertions(+), 61 deletions(-) create mode 100644 htdocs/install/mysql/tables/llx_holiday.key.sql create mode 100644 htdocs/install/mysql/tables/llx_holiday_events.key.sql diff --git a/htdocs/holiday/admin/holiday.php b/htdocs/holiday/admin/holiday.php index dbb8dc67d74..c7ecb17f1da 100644 --- a/htdocs/holiday/admin/holiday.php +++ b/htdocs/holiday/admin/holiday.php @@ -32,6 +32,8 @@ require_once DOL_DOCUMENT_ROOT. '/user/class/user.class.php'; require_once DOL_DOCUMENT_ROOT. '/user/class/usergroup.class.php'; $action=GETPOST('action'); +$optName=GETPOST('optName'); +$optValue=GETPOST('optValue'); $langs->load("admin"); $langs->load("holiday"); @@ -155,7 +157,6 @@ if ($action == "add") $message.= '
'.$langs->trans('AddCPforUsers').'
'; } - dol_htmloutput_mesg($message); @@ -163,45 +164,41 @@ if ($action == "add") } elseif ($action == 'create_event') { - $error = false; + $error = 0; - if (!empty($_POST['optName'])) + $optName = trim($optName); + $optValue = price2num($optValue,2); + + if (! $optName) { - $optName = trim($_POST['optName']); - } else { - $error = true; + $message='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Name")).'
'; + $error++; } - - if (!empty($_POST['optValue'])) + if (! $optValue > 0) { - $optValue = price2num($_POST['optValue'],2); - } else { - $error = true; + $message='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Value")).'
'; + $error++; } $cp->optName = $optName; $cp->optValue = $optValue; - if($error) - { - $message = 'ErrorCreateEventCP'; - } - else + if (! $error) { $result = $cp->createEventCP($user); - if($result > 0) { $message = 'OkCreateEventCP'; + $optName=''; + $optValue=''; } else { - $message = 'ErrorCreateEventCP'; + $message = '
'.$cp->error.'
'; } } dol_htmloutput_mesg($message); - } elseif($action == 'event' && isset($_POST['update_event'])) { @@ -210,10 +207,10 @@ elseif($action == 'event' && isset($_POST['update_event'])) $eventId = array_keys($_POST['update_event']); $eventId = $eventId[0]; - $eventName = $_POST['optName']; + $eventName = $optName; $eventName = $eventName[$eventId]; - $eventValue = $_POST['optValue']; + $eventValue = $optValue; $eventValue = $eventValue[$eventId]; if(!empty($eventName)) { @@ -242,7 +239,6 @@ elseif($action == 'event' && isset($_POST['update_event'])) } dol_htmloutput_mesg($message); - } elseif($action && isset($_POST['delete_event'])) { @@ -353,16 +349,14 @@ if($cp_events == 1) { print '
'."\n"; print ''."\n"; - print '
'.$langs->trans('TitleUpdateEventCP').'
'."\n"; - print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; print ''."\n"; @@ -373,7 +367,7 @@ if($cp_events == 1) { print ''."\n"; print ''."\n"; print ''."\n"; - print ''."\n"; + print ''."\n"; print ''."\n"; print ''; @@ -388,6 +382,7 @@ if($cp_events == 1) { } print ''."\n"; +print ''."\n"; print $langs->trans('TitleCreateEventCP'); @@ -398,16 +393,14 @@ print ''; print ''; print ''; -print ''; +print ''; print ''; -print ''."\n"; - print ''; -print ''."\n"; -print ''."\n"; -print ''."\n"; +print ''."\n"; +print ''."\n"; +print ''."\n"; print ''."\n"; print ''; diff --git a/htdocs/install/mysql/tables/llx_holiday.key.sql b/htdocs/install/mysql/tables/llx_holiday.key.sql new file mode 100644 index 00000000000..c4f4023da97 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_holiday.key.sql @@ -0,0 +1,21 @@ +-- =================================================================== +-- Copyright (C) 2012 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 +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- =================================================================== + +ALTER TABLE llx_holiday ADD INDEX idx_holiday_fk_user (fk_user); +ALTER TABLE llx_holiday ADD INDEX idx_holiday_date_debut (date_debut); +ALTER TABLE llx_holiday ADD INDEX idx_holiday_date_fin (date_fin); diff --git a/htdocs/install/mysql/tables/llx_holiday.sql b/htdocs/install/mysql/tables/llx_holiday.sql index 637d0903ad6..935de76ef9e 100644 --- a/htdocs/install/mysql/tables/llx_holiday.sql +++ b/htdocs/install/mysql/tables/llx_holiday.sql @@ -1,19 +1,19 @@ CREATE TABLE llx_holiday ( -rowid INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY, -fk_user INT( 11 ) NOT NULL , -date_create DATETIME NOT NULL , -description VARCHAR( 255 ) NOT NULL , -date_debut DATE NOT NULL , -date_fin DATE NOT NULL , -statut INT( 11 ) NOT NULL DEFAULT '1', -fk_validator INT( 11 ) NOT NULL , -date_valid DATETIME NULL DEFAULT NULL , -fk_user_valid INT( 11 ) NULL DEFAULT NULL , -date_refuse DATETIME NULL DEFAULT NULL , -fk_user_refuse INT( 11 ) NULL DEFAULT NULL , -date_cancel DATETIME NULL DEFAULT NULL , -fk_user_cancel INT( 11 ) NULL DEFAULT NULL, -detail_refuse varchar( 250 ) NULL DEFAULT NULL +rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY, +fk_user integer NOT NULL, +date_create DATETIME NOT NULL, +description VARCHAR( 255 ) NOT NULL, +date_debut DATE NOT NULL, +date_fin DATE NOT NULL, +statut integer NOT NULL DEFAULT '1', +fk_validator integer NOT NULL, +date_valid DATETIME DEFAULT NULL, +fk_user_valid integer DEFAULT NULL, +date_refuse DATETIME DEFAULT NULL, +fk_user_refuse integer DEFAULT NULL, +date_cancel DATETIME DEFAULT NULL, +fk_user_cancel integer DEFAULT NULL, +detail_refuse varchar( 250 ) DEFAULT NULL ) ENGINE=innodb; \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_holiday_config.sql b/htdocs/install/mysql/tables/llx_holiday_config.sql index ea4a1cf767b..a90902f62c1 100644 --- a/htdocs/install/mysql/tables/llx_holiday_config.sql +++ b/htdocs/install/mysql/tables/llx_holiday_config.sql @@ -1,6 +1,24 @@ +-- =================================================================== +-- Copyright (C) 2012 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 +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- =================================================================== + CREATE TABLE llx_holiday_config ( -rowid INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY, +rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR( 255 ) NOT NULL UNIQUE, value TEXT NULL ) diff --git a/htdocs/install/mysql/tables/llx_holiday_events.key.sql b/htdocs/install/mysql/tables/llx_holiday_events.key.sql new file mode 100644 index 00000000000..2193c9272b9 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_holiday_events.key.sql @@ -0,0 +1,19 @@ +-- =================================================================== +-- Copyright (C) 2012 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 +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- =================================================================== + +ALTER TABLE llx_holiday_events ADD UNIQUE INDEX uk_holiday_name (name, entity); diff --git a/htdocs/install/mysql/tables/llx_holiday_events.sql b/htdocs/install/mysql/tables/llx_holiday_events.sql index 0445bd7c6e4..9a45bf882d4 100644 --- a/htdocs/install/mysql/tables/llx_holiday_events.sql +++ b/htdocs/install/mysql/tables/llx_holiday_events.sql @@ -1,7 +1,26 @@ +-- =================================================================== +-- Copyright (C) 2012 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 +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- =================================================================== + CREATE TABLE llx_holiday_events ( -rowid INT( 11 ) NOT NULL PRIMARY KEY AUTO_INCREMENT , -name VARCHAR( 255 ) NOT NULL , -value TEXT NOT NULL + rowid integer NOT NULL PRIMARY KEY AUTO_INCREMENT, + entity integer DEFAULT 1 NOT NULL, -- multi company id + name VARCHAR( 255 ) NOT NULL, + value TEXT NOT NULL ) ENGINE=innodb; \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_holiday_logs.sql b/htdocs/install/mysql/tables/llx_holiday_logs.sql index de70b4e370d..31310903f58 100644 --- a/htdocs/install/mysql/tables/llx_holiday_logs.sql +++ b/htdocs/install/mysql/tables/llx_holiday_logs.sql @@ -1,11 +1,29 @@ +-- =================================================================== +-- Copyright (C) 2012 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 +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- =================================================================== + CREATE TABLE llx_holiday_logs ( -rowid INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY , -date_action DATETIME NOT NULL , -fk_user_action INT( 11 ) NOT NULL , -fk_user_update INT( 11 ) NOT NULL , -type_action VARCHAR( 255 ) NOT NULL , -prev_solde VARCHAR( 255 ) NOT NULL , +rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY, +date_action DATETIME NOT NULL, +fk_user_action integer NOT NULL, +fk_user_update integer NOT NULL, +type_action VARCHAR( 255 ) NOT NULL, +prev_solde VARCHAR( 255 ) NOT NULL, new_solde VARCHAR( 255 ) NOT NULL ) ENGINE=innodb; \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_holiday_users.sql b/htdocs/install/mysql/tables/llx_holiday_users.sql index cf41254e911..a6aa6bd91d6 100644 --- a/htdocs/install/mysql/tables/llx_holiday_users.sql +++ b/htdocs/install/mysql/tables/llx_holiday_users.sql @@ -1,6 +1,6 @@ CREATE TABLE llx_holiday_users ( -fk_user INT( 11 ) NOT NULL PRIMARY KEY, -nb_holiday FLOAT( 5 ) NOT NULL DEFAULT '0' +fk_user integer NOT NULL PRIMARY KEY, +nb_holiday real NOT NULL DEFAULT '0' ) ENGINE=innodb; \ No newline at end of file
'.$langs->trans('NameEventCP').''.$langs->trans('ValueOptionCP').''.$langs->trans('UpdateEventOptionCP').''.$langs->trans('DeleteEventOptionCP').''.$langs->trans('ValueOptionCP').'  
'.$langs->trans('Jours').'
'.$langs->trans('NameEventCP').''.$langs->trans('ValueOptionCP').''.$langs->trans('CreateEventCP').' 
'.$langs->trans('Jours').' '.$langs->trans('Jours').'