From 59627408c0ec7570ef687d25cde44880d4c337ba Mon Sep 17 00:00:00 2001 From: jfefe Date: Mon, 4 Mar 2013 19:17:11 +0100 Subject: [PATCH] Edit extrafields on propal --- htdocs/comm/propal.php | 66 ++++++++++++++++++++++- htdocs/comm/propal/class/propal.class.php | 38 +++++++++++++ 2 files changed, 103 insertions(+), 1 deletion(-) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index eefc7a9ed8e..b2dc55cc67d 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -1096,6 +1096,36 @@ else if ($action == 'down' && $user->rights->propal->creer) header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.'#'.GETPOST('rowid')); exit; } +else if ($action == 'update_extras') +{ + // Get extra fields + foreach($_POST as $key => $value) + { + if (preg_match("/^options_/",$key)) + { + $object->array_options[$key]=$_POST[$key]; + } + } + + // Actions on extra fields (by external module or standard code) + // FIXME le hook fait double emploi avec le trigger !! + $hookmanager->initHooks(array('propaldao')); + $parameters=array('id'=>$object->id); + $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks + if (empty($reshook)) + { + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + $result=$object->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + } + else if ($reshook < 0) $error++; + +} if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->propal->creer) { @@ -1798,19 +1828,53 @@ else } // Other attributes + $res=$object->fetch_optionals($object->id,$extralabels); $parameters=array('colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook if (empty($reshook) && ! empty($extrafields->attribute_label)) { + + if ($action == 'edit_extras') + { + print '
'; + print ''; + print ''; + print ''; + } + + foreach($extrafields->attribute_label as $key=>$label) { $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); print 'attribute_required[$key])) print ' class="fieldrequired"'; print '>'.$label.''; - print $extrafields->showInputField($key,$value); + if ($action == 'edit_extras') + { + print $extrafields->showInputField($key,$value); + } + else + { + print $extrafields->showOutputField($key,$value); + } + print ''."\n"; } + + if(count($extrafields->attribute_label) > 0) { + + if ($action == 'edit_extras') + { + print ''; + print ''; + print ''; + print ''; + + } + else { + print ''.img_picto('','edit').' Modifier les valeurs'; + } + } } // Amount HT diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 8d96690e9dd..7722900a1dc 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1176,6 +1176,44 @@ class Propal extends CommonObject return -1; } } + + /** + * Update value of extrafields on the proposal + * + * @param User $user Object user that modify + * @param double $remise Amount discount + * @return int <0 if ko, >0 if ok + */ + function update_extrafields($user) + { + // Actions on extra fields (by external module or standard code) + // FIXME le hook fait double emploi avec le trigger !! + $hookmanager->initHooks(array('propaldao')); + $parameters=array('id'=>$this->id); + $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if (empty($reshook)) + { + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + $result=$this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + } + else if ($reshook < 0) $error++; + + if (!$error) + { + return 1; + } + else + { + return -1; + } + + } /** * Set status to validated