Qual: Uniformize error management, add transaction level

Fix: Could not reset birthday
This commit is contained in:
Laurent Destailleur
2010-11-19 21:24:48 +00:00
parent 2468ae22ab
commit df677b07b0
6 changed files with 322 additions and 237 deletions

View File

@@ -454,8 +454,8 @@ class ActionComm extends CommonObject
/**
* \brief Charge les informations d'ordre info dans l'objet facture
* \param id Id de la facture a charger
* Charge les informations d'ordre info dans l'objet facture
* @param id Id de la facture a charger
*/
function info($id)
{
@@ -502,9 +502,9 @@ class ActionComm extends CommonObject
/**
* \brief Retourne le libelle du statut de la commande
* \param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
* \return string Libelle
* Return label of status
* @param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
* @return string Libelle
*/
function getLibStatut($mode)
{
@@ -512,10 +512,10 @@ class ActionComm extends CommonObject
}
/**
* \brief Renvoi le libelle d'un statut donne
* \param percent Pourcentage avancement
* \param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
* \return string Libelle
* Return label of action status
* @param percent Percent
* @param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
* @return string Label
*/
function LibStatut($percent,$mode)
{
@@ -523,7 +523,7 @@ class ActionComm extends CommonObject
if ($mode == 0)
{
if ($percent==0) return $langs->trans('StatusActionToDo');
if ($percent==0) return $langs->trans('StatusActionToDo').' (0%)';
if ($percent > 0 && $percent < 100) return $langs->trans('StatusActionInProcess').' ('.$percent.'%)';
if ($percent >= 100) return $langs->trans('StatusActionDone').' (100%)';
}
@@ -541,9 +541,9 @@ class ActionComm extends CommonObject
}
if ($mode == 3)
{
if ($percent==0) return img_picto($langs->trans("Status").': '.$langs->trans('StatusActionToDo'),'statut1');
if ($percent==0) return img_picto($langs->trans("Status").': '.$langs->trans('StatusActionToDo').' (0%)','statut1');
if ($percent > 0 && $percent < 100) return img_picto($langs->trans("Status").': '.$langs->trans('StatusActionInProcess').' ('.$percent.'%)','statut3');
if ($percent >= 100) return img_picto($langs->trans("Status").': '.$langs->trans('StatusActionDone'),'statut6');
if ($percent >= 100) return img_picto($langs->trans("Status").': '.$langs->trans('StatusActionDone').' (100%)','statut6');
}
if ($mode == 4)
{
@@ -560,20 +560,20 @@ class ActionComm extends CommonObject
}
/**
* \brief Renvoie nom clicable (avec eventuellement le picto)
* \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
* \param maxlength Nombre de caracteres max dans libelle
* \param class Force style class on a link
* \param option ''=Link to action,'birthday'=Link to contact
* \return string Chaine avec URL
* \remarks Utilise $this->id, $this->code et $this->libelle
* Renvoie nom clicable (avec eventuellement le picto)
* @param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
* @param maxlength Nombre de caracteres max dans libelle
* @param class Force style class on a link
* @param option ''=Link to action,'birthday'=Link to contact
* @return string Chaine avec URL
* @remarks Utilise $this->id, $this->code et $this->libelle
*/
function getNomUrl($withpicto=0,$maxlength=0,$classname='',$option='')
{
global $langs;
$result='';
if ($option=='birthday') $lien = '<a '.($classname?'class="'.$classname.'" ':'').'href="'.DOL_URL_ROOT.'/contact/perso.php?id='.$this->id.'">';
if ($option=='birthday') $lien = '<a '.($classname?'class="'.$classname.'" ':'').'href="'.DOL_URL_ROOT.'/contact/perso.php?id='.$this->id.'">'.img_object('','contact').' ';
else $lien = '<a '.($classname?'class="'.$classname.'" ':'').'href="'.DOL_URL_ROOT.'/comm/action/fiche.php?id='.$this->id.'">';
$lienfin='</a>';

View File

@@ -22,7 +22,7 @@
/**
* \file htdocs/comm/action/index.php
* \ingroup agenda
* \brief Page accueil des rapports des actions
* \brief Home page of calendar events
* \version $Id$
*/
@@ -580,6 +580,7 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$action
print $action->getNomUrl(0,$nbofchartoshow,'cal_event','birthday');
}
print '</td>';
// Status - Percent
print '<td align="right" nowrap="nowrap">';
if ($action->type_code != 'BIRTHDAY') print $action->getLibStatut(3);
else print '&nbsp;';

View File

@@ -77,9 +77,9 @@ class Contact extends CommonObject
/**
* \brief Constructeur de l'objet contact
* \param DB Habler d'acces base
* \param id Id contact
* Constructor of class Contact
* @param DB Habler d'acces base
* @param id Id contact
*/
function Contact($DB, $id=0)
{
@@ -90,16 +90,19 @@ class Contact extends CommonObject
}
/**
* \brief Add a contact into database
* \param user Object user that create
* \return int <0 if KO, >0 if OK
* Add a contact into database
* @param user Object user that create
* @return int <0 if KO, >0 if OK
*/
function create($user)
{
global $conf, $langs;
$error=0;
$now=dol_now();
$this->db->begin();
// Clean parameters
$this->name=trim($this->name);
if (! $this->socid) $this->socid = 0;
@@ -122,36 +125,64 @@ class Contact extends CommonObject
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."socpeople");
$result=$this->update($this->id, $user, 1);
if ($result < 0)
if (! $error)
{
$this->error=$this->db->error();
return -2;
$result=$this->update($this->id, $user, 1);
if ($result < 0)
{
$error++;
$this->error=$this->db->lasterror();
}
}
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('CONTACT_CREATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
if (! $error)
{
$result=$this->update_perso($this->id, $user);
if ($result < 0)
{
$error++;
$this->error=$this->db->lasterror();
}
}
return $this->id;
if (! $error)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('CONTACT_CREATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
}
if (! $error)
{
$this->db->commit();
return $this->id;
}
else
{
$this->db->rollback();
dol_syslog("Contact::create ".$this->error, LOG_ERR);
return -2;
}
}
else
{
$this->error=$this->db->error();
$this->error=$this->db->lasterror();
$this->db->rollback();
dol_syslog("Contact::create ".$this->error, LOG_ERR);
return -1;
}
}
/**
* \brief Update informations into database
* \param id Id du contact a mettre a jour
* \param user Objet utilisateur qui effectue la mise a jour
* \param notrigger 0=non, 1=oui
* \return int <0 if KO, >0 if OK
* Update informations into database
* @param id Id du contact a mettre a jour
* @param user Objet utilisateur qui effectue la mise a jour
* @param notrigger 0=non, 1=oui
* @return int <0 if KO, >0 if OK
*/
function update($id, $user=0, $notrigger=0)
{
@@ -226,10 +257,9 @@ class Contact extends CommonObject
}
else
{
$this->db->rollback();
$this->error=$this->db->lasterror().' sql='.$sql;
dol_syslog("Contact::update Error ".$this->error,LOG_ERR);
$this->db->rollback();
return -1;
}
}
@@ -323,29 +353,20 @@ class Contact extends CommonObject
}
/*
* \brief Mise a jour des alertes
* \param id id du contact
* \param user Utilisateur qui demande l'alerte
/**
* Update field alert birthday
* @param id Id of contact
* @param user User asking to change alert or birthday
* @return int
*/
function update_perso($id, $user=0)
{
$error=0;
$result=false;
// Mis a jour contact
$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET rowid=".$id;
if ($this->birthday) // <0 si avant 1970, >0 si apres 1970
{
if (preg_match('/^[0-9]+\-/',$this->birthday))
{
// Si date = chaine (ne devrait pas arriver)
$sql .= ", birthday='".$this->birthday."'";
}
else
{
// Si date = timestamp
$sql .= ", birthday=".$this->db->idate($this->birthday);
}
}
$sql .= ", birthday=".($this->birthday ? "'".$this->db->idate($this->birthday)."'" : "null");
if ($user) $sql .= ", fk_user_modif=".$user->id;
$sql .= " WHERE rowid=".$id;
//print "update_perso: ".$this->birthday.'-'.$this->db->idate($this->birthday);
@@ -353,7 +374,8 @@ class Contact extends CommonObject
$resql = $this->db->query($sql);
if (! $resql)
{
$this->error=$this->db->error();
$error++;
$this->error=$this->db->lasterror();
}
// Mis a jour alerte birthday
@@ -370,7 +392,8 @@ class Contact extends CommonObject
$result = $this->db->query($sql);
if (!$result)
{
$this->error='Echec sql='.$sql;
$error++;
$this->error=$this->db->lasterror();
}
}
else
@@ -383,11 +406,13 @@ class Contact extends CommonObject
$sql = "DELETE from ".MAIN_DB_PREFIX."user_alert ";
$sql.= "where type=1 AND fk_contact=".$id." AND fk_user=".$user->id;
$result = $this->db->query($sql);
if (!$result)
if (! $result)
{
$this->error='Echec sql='.$sql;
$error++;
$this->error=$this->db->lasterror();
}
}
return $result;
}

View File

@@ -89,13 +89,13 @@ else
{
// Recuperation contact actuel
$result = $object->fetch($_GET["id"]);
if ($result > 0)
{
// Creation user
$nuser = new User($db);
$result=$nuser->create_from_contact($object,$_POST["login"]);
if ($result < 0)
{
$msg=$nuser->error;
@@ -106,12 +106,16 @@ else
$msg=$object->error;
}
}
// Creation contact
if ($_POST["action"] == 'add' && $user->rights->societe->contact->creer)
{
$error=0;
$db->begin();
$object->socid = $_POST["socid"];
$object->name = $_POST["name"];
$object->firstname = $_POST["firstname"];
$object->civilite_id = $_POST["civilite_id"];
@@ -129,36 +133,48 @@ else
$object->jabberid = $_POST["jabberid"];
$object->priv = $_POST["priv"];
$object->note = $_POST["note"];
// Note: Correct date should be completed with location to have exact GM time of birth.
$object->birthday = dol_mktime(0,0,0,$_POST["birthdaymonth"],$_POST["birthdayday"],$_POST["birthdayyear"]);
$object->birthday_alert = $_POST["birthday_alert"];
if (! $_POST["name"])
{
$error++;
array_push($errors,$langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label")));
$_GET["action"] = $_POST["action"] = 'create';
}
if ($_POST["name"])
{
$id = $object->create($user);
if ($id > 0)
if ($id <= 0)
{
Header("Location: fiche.php?id=".$id);
exit;
}
else
{
$errors=array($object->error);
$error++;
$errors=array($object->error);
$_GET["action"] = $_POST["action"] = 'create';
}
}
if (! $error && $id > 0)
{
$db->commit();
Header("Location: fiche.php?id=".$id);
exit;
}
else
{
$db->rollback();
}
}
if (GETPOST("action") == 'confirm_delete' && GETPOST("confirm") == 'yes' && $user->rights->societe->contact->supprimer)
{
$result=$object->fetch($_GET["id"]);
$object->old_name = $_POST["old_name"];
$object->old_firstname = $_POST["old_firstname"];
$result = $object->delete();
if ($result > 0)
{
@@ -170,7 +186,7 @@ else
$mesg=$object->error;
}
}
if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer)
{
if (empty($_POST["name"]))
@@ -179,28 +195,28 @@ else
$error++;
$_GET["action"] = $_POST["action"] = 'edit';
}
if (! sizeof($errors))
{
$object->fetch($_POST["contactid"]);
$object->oldcopy=dol_clone($object);
$object->old_name = $_POST["old_name"];
$object->old_firstname = $_POST["old_firstname"];
$object->socid = $_POST["socid"];
$object->name = $_POST["name"];
$object->firstname = $_POST["firstname"];
$object->civilite_id = $_POST["civilite_id"];
$object->poste = $_POST["poste"];
$object->address = $_POST["address"];
$object->cp = $_POST["cp"];
$object->ville = $_POST["ville"];
$object->fk_departement= $_POST["departement_id"];
$object->fk_pays = $_POST["pays_id"];
$object->email = $_POST["email"];
$object->phone_pro = $_POST["phone_pro"];
$object->phone_perso = $_POST["phone_perso"];
@@ -209,9 +225,9 @@ else
$object->jabberid = $_POST["jabberid"];
$object->priv = $_POST["priv"];
$object->note = $_POST["note"];
$result = $object->update($_POST["contactid"], $user);
if ($result > 0)
{
$object->old_name='';
@@ -248,25 +264,25 @@ if (! empty($canvas))
// -----------------------------------------
// When used with CANVAS
// -----------------------------------------
if (GETPOST("action") == 'create')
{
// Set action type
$objcanvas->setAction(GETPOST("action"));
// Card header
$title = $objcanvas->getTitle();
print_fiche_titre($title);
// Assign _POST data
$objcanvas->assign_post();
// Assign template values
$objcanvas->assign_values();
// Show errors
dol_htmloutput_errors($objcanvas->error,$objcanvas->errors);
// Display canvas
$objcanvas->display_canvas();
}
@@ -275,26 +291,26 @@ if (! empty($canvas))
/*
* Mode edition
*/
// Set action type
$objcanvas->setAction(GETPOST("action"));
// Fetch object
$result=$objcanvas->fetch($id);
if ($result > 0)
{
// Card header
$objcanvas->showHead();
if ($_POST["name"])
{
// Assign _POST data
$objcanvas->assign_post();
}
// Assign values
$objcanvas->assign_values();
// Display canvas
$objcanvas->display_canvas();
}
@@ -303,12 +319,12 @@ if (! empty($canvas))
dol_htmloutput_errors($objcanvas->error,$objcanvas->errors);
}
}
if (GETPOST("id") && GETPOST("action") != 'edit')
{
// Set action type
$objcanvas->setAction('view');
// Fetch object
$result=$objcanvas->fetch($id);
if ($result > 0)
@@ -318,30 +334,30 @@ if (! empty($canvas))
// Assign values
$objcanvas->assign_values();
//Show errors
dol_htmloutput_errors($objcanvas->error,$objcanvas->errors);
// Display canvas
$objcanvas->display_canvas();
print show_actions_todo($conf,$langs,$db,$objsoc,$objcanvas->control->object);
print show_actions_done($conf,$langs,$db,$objsoc,$objcanvas->control->object);
}
else
{
dol_htmloutput_errors($objcanvas->error,$objcanvas->errors);
}
}
}
}
else
{
// -----------------------------------------
// When used in standard mode
// -----------------------------------------
/*
* Confirmation de la suppression du contact
*/
@@ -353,29 +369,29 @@ else
if ($ret == 'html') print '<br>';
}
}
/*
* Onglets
*/
if ($_GET["id"] > 0)
if (GETPOST("id") > 0)
{
// Si edition contact deja existant
$contact = new Contact($db);
$return=$contact->fetch($_GET["id"], $user);
$object = new Contact($db);
$return=$object->fetch(GETPOST("id"), $user);
if ($return <= 0)
{
dol_print_error('',$contact->error);
dol_print_error('',$object->error);
$_GET["id"]=0;
}
/*
* Affichage onglets
*/
$head = contact_prepare_head($contact);
$head = contact_prepare_head($object);
dol_fiche_head($head, 'card', $langs->trans("Contact"), 0, 'contact');
}
if ($user->rights->societe->contact->creer)
{
if (GETPOST("action") == 'create')
@@ -384,7 +400,7 @@ else
* Fiche en mode creation
*/
$object->fk_departement = $_POST["departement_id"];
// We set pays_id, pays_code and label for the selected country
$object->fk_pays=$_POST["pays_id"]?$_POST["pays_id"]:$mysoc->pays_id;
if ($object->fk_pays)
@@ -404,12 +420,12 @@ else
$object->pays_code=$obj->code;
$object->pays=$obj->libelle;
}
print_fiche_titre($langs->trans("AddContact"));
// Affiche les erreurs
dol_htmloutput_errors($mesg,$errors);
if ($conf->use_javascript_ajax)
{
print "\n".'<script type="text/javascript" language="javascript">';
@@ -421,17 +437,17 @@ else
})';
print '</script>'."\n";
}
print '<br>';
print '<form method="post" name="formsoc" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="add">';
print '<table class="border" width="100%">';
// Name
print '<tr><td width="15%" class="fieldrequired">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td><input name="name" type="text" size="30" maxlength="80" value="'.(isset($_POST["name"])?$_POST["name"]:$object->name).'"></td>';
print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="25%"><input name="firstname" type="text" size="30" maxlength="80" value="'.(isset($_POST["firstname"])?$_POST["firstname"]:$object->firstname).'"></td></tr>';
print '<tr><td width="20%" class="fieldrequired">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td width="30%"><input name="name" type="text" size="30" maxlength="80" value="'.(isset($_POST["name"])?$_POST["name"]:$object->name).'"></td>';
print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="30%"><input name="firstname" type="text" size="30" maxlength="80" value="'.(isset($_POST["firstname"])?$_POST["firstname"]:$object->firstname).'"></td></tr>';
// Company
if ($socid > 0)
{
@@ -449,31 +465,31 @@ else
//print $langs->trans("ContactNotLinkedToCompany");
print '</td></tr>';
}
// Civility
print '<tr><td width="15%">'.$langs->trans("UserTitle").'</td><td colspan="3">';
print $formcompany->select_civilite(isset($_POST["civilite_id"])?$_POST["civilite_id"]:$object->civilite_id);
print '</td></tr>';
print '<tr><td>'.$langs->trans("PostOrFunction").'</td><td colspan="3"><input name="poste" type="text" size="50" maxlength="80" value="'.(isset($_POST["poste"])?$_POST["poste"]:$object->poste).'"></td>';
// Address
if (($objsoc->typent_code == 'TE_PRIVATE') && dol_strlen(trim($object->address)) == 0) $object->address = $objsoc->address; // Predefined with third party
print '<tr><td>'.$langs->trans("Address").'</td><td colspan="3"><textarea class="flat" name="address" cols="70">'.(isset($_POST["address"])?$_POST["address"]:$object->address).'</textarea></td>';
// Zip / Town
if (($objsoc->typent_code == 'TE_PRIVATE') && dol_strlen(trim($object->cp)) == 0) $object->cp = $objsoc->cp; // Predefined with third party
if (($objsoc->typent_code == 'TE_PRIVATE') && dol_strlen(trim($object->ville)) == 0) $object->ville = $objsoc->ville; // Predefined with third party
print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td colspan="3"><input name="cp" type="text" size="6" maxlength="80" value="'.(isset($_POST["cp"])?$_POST["cp"]:$object->cp).'">&nbsp;';
print '<input name="ville" type="text" size="20" value="'.(isset($_POST["ville"])?$_POST["ville"]:$object->ville).'" maxlength="80"></td></tr>';
// Country
if (dol_strlen(trim($object->fk_pays)) == 0) $object->fk_pays = $objsoc->pays_id; // Predefined with third party
print '<tr><td>'.$langs->trans("Country").'</td><td colspan="3">';
$form->select_pays((isset($_POST["pays_id"])?$_POST["pays_id"]:$object->fk_pays),'pays_id');
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
print '</td></tr>';
// State
print '<tr><td>'.$langs->trans('State').'</td><td colspan="3">';
if ($object->fk_pays)
@@ -485,35 +501,69 @@ else
print $countrynotdefined;
}
print '</td></tr>';
// Phone / Fax
if (($objsoc->typent_code == 'TE_PRIVATE') && dol_strlen(trim($object->phone_pro)) == 0) $object->phone_pro = $objsoc->tel; // Predefined with third party
print '<tr><td>'.$langs->trans("PhonePro").'</td><td><input name="phone_pro" type="text" size="18" maxlength="80" value="'.(isset($_POST["phone_pro"])?$_POST["phone_pro"]:$object->phone_pro).'"></td>';
print '<td>'.$langs->trans("PhonePerso").'</td><td><input name="phone_perso" type="text" size="18" maxlength="80" value="'.(isset($_POST["phone_perso"])?$_POST["phone_perso"]:$object->phone_perso).'"></td></tr>';
if (($objsoc->typent_code == 'TE_PRIVATE') && dol_strlen(trim($object->fax)) == 0) $object->fax = $objsoc->fax; // Predefined with third party
print '<tr><td>'.$langs->trans("PhoneMobile").'</td><td><input name="phone_mobile" type="text" size="18" maxlength="80" value="'.(isset($_POST["phone_mobile"])?$_POST["phone_mobile"]:$object->phone_mobile).'"></td>';
print '<td>'.$langs->trans("Fax").'</td><td><input name="fax" type="text" size="18" maxlength="80" value="'.(isset($_POST["fax"])?$_POST["fax"]:$object->fax).'"></td></tr>';
// EMail
if (($objsoc->typent_code == 'TE_PRIVATE') && dol_strlen(trim($object->email)) == 0) $object->email = $objsoc->email; // Predefined with third party
print '<tr><td>'.$langs->trans("Email").'</td><td colspan="3"><input name="email" type="text" size="50" maxlength="80" value="'.(isset($_POST["email"])?$_POST["email"]:$object->email).'"></td></tr>';
// Jabberid
print '<tr><td>Jabberid</td><td colspan="3"><input name="jabberid" type="text" size="50" maxlength="80" value="'.(isset($_POST["jabberid"])?$_POST["jabberid"]:$object->jabberid).'"></td></tr>';
// Visibility
print '<tr><td>'.$langs->trans("ContactVisibility").'</td><td colspan="3">';
$selectarray=array('0'=>$langs->trans("ContactPublic"),'1'=>$langs->trans("ContactPrivate"));
print $form->selectarray('priv',$selectarray,(isset($_POST["priv"])?$_POST["priv"]:$object->priv),0);
print '</td></tr>';
// Note
print '<tr><td valign="top">'.$langs->trans("Note").'</td><td colspan="3" valign="top"><textarea name="note" cols="70" rows="'.ROWS_3.'">'.(isset($_POST["note"])?$_POST["note"]:$object->note).'</textarea></td></tr>';
print '<tr><td align="center" colspan="4"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td></tr>';
print "</table><br>";
print "</table><br>";
// Add personnal information
print_fiche_titre('<div class="comboperso">'.$langs->trans("PersonalInformations").'</div>','','');
print '<table class="border" width="100%">';
// Date To Birth
print '<tr><td width="20%">'.$langs->trans("DateToBirth").'</td><td width="30%">';
$html=new Form($db);
if ($object->birthday)
{
print $html->select_date($object->birthday,'birthday',0,0,0,"perso");
}
else
{
print $html->select_date('','birthday',0,0,1,"perso");
}
print '</td>';
print '<td colspan="2">'.$langs->trans("Alert").': ';
if ($object->birthday_alert)
{
print '<input type="checkbox" name="birthday_alert" checked></td>';
}
else
{
print '<input type="checkbox" name="birthday_alert"></td>';
}
print '</tr>';
print "</table><br>";
print '<center><input type="submit" class="button" value="'.$langs->trans("Add").'"></center>';
print "</form>";
}
elseif (GETPOST("action") == 'edit' && GETPOST("id"))
@@ -521,7 +571,7 @@ else
/*
* Fiche en mode edition
*/
// We set pays_id, and pays_code label of the chosen country
if (isset($_POST["pays_id"]) || $object->fk_pays)
{
@@ -538,22 +588,22 @@ else
$object->pays_code=$obj->code;
$object->pays=$langs->trans("Country".$obj->code)?$langs->trans("Country".$obj->code):$obj->libelle;
}
// Affiche les erreurs
dol_htmloutput_errors($mesg,$errors);
if ($conf->use_javascript_ajax)
{
print "\n".'<script type="text/javascript" language="javascript">';
print '<script type="text/javascript" language="javascript">';
print 'jQuery(document).ready(function () {
jQuery("#selectpays_id").change(function() {
document.formsoc.action.value="edit";
document.formsoc.submit();
});
})';
print '</script>'."\n";
print '</script>';
}
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?id='.GETPOST("id").'" name="formsoc">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="id" value="'.GETPOST("id").'">';
@@ -562,55 +612,55 @@ else
print '<input type="hidden" name="old_name" value="'.$object->name.'">';
print '<input type="hidden" name="old_firstname" value="'.$object->firstname.'">';
print '<table class="border" width="100%">';
// Ref
print '<tr><td>'.$langs->trans("Ref").'</td><td colspan="3">';
print $object->ref;
print '</td></tr>';
// Name
print '<tr><td class="fieldrequired">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td><input name="name" type="text" size="20" maxlength="80" value="'.(isset($_POST["name"])?$_POST["name"]:$object->name).'"></td>';
print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="25%"><input name="firstname" type="text" size="20" maxlength="80" value="'.(isset($_POST["firstname"])?$_POST["firstname"]:$object->firstname).'"></td></tr>';
print '<tr><td width="20%" class="fieldrequired">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td width="30%"><input name="name" type="text" size="20" maxlength="80" value="'.(isset($_POST["name"])?$_POST["name"]:$object->name).'"></td>';
print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="30%"><input name="firstname" type="text" size="20" maxlength="80" value="'.(isset($_POST["firstname"])?$_POST["firstname"]:$object->firstname).'"></td></tr>';
// Company
print '<tr><td width="20%">'.$langs->trans("Company").'</td>';
print '<tr><td>'.$langs->trans("Company").'</td>';
print '<td colspan="3">';
print $form->select_societes(isset($_POST["socid"])?$_POST["socid"]:($object->socid?$object->socid:-1),'socid','',1);
print '</td>';
print '</tr>';
// Civility
print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
print $formcompany->select_civilite(isset($_POST["civilite_id"])?$_POST["civilite_id"]:$object->civilite_id);
print '</td></tr>';
print '<tr><td>'.$langs->trans("PostOrFunction" ).'</td><td colspan="3"><input name="poste" type="text" size="50" maxlength="80" value="'.(isset($_POST["poste"])?$_POST["poste"]:$object->poste).'"></td></tr>';
// Address
print '<tr><td>'.$langs->trans("Address").'</td><td colspan="3"><textarea class="flat" name="address" cols="70">'.(isset($_POST["address"])?$_POST["address"]:$object->address).'</textarea></td>';
// Zip / Town
print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td colspan="3"><input name="cp" type="text" size="6" maxlength="80" value="'.(isset($_POST["cp"])?$_POST["cp"]:$object->cp).'">&nbsp;';
print '<input name="ville" type="text" size="20" value="'.(isset($_POST["ville"])?$_POST["ville"]:$object->ville).'" maxlength="80"></td></tr>';
// Country
print '<tr><td>'.$langs->trans("Country").'</td><td colspan="3">';
$form->select_pays(isset($_POST["pays_id"])?$_POST["pays_id"]:$object->fk_pays,'pays_id');
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
print '</td></tr>';
// Department
print '<tr><td>'.$langs->trans('State').'</td><td colspan="3">';
$formcompany->select_departement($object->fk_departement,$object->pays_code);
print '</td></tr>';
// Phone
print '<tr><td>'.$langs->trans("PhonePro").'</td><td><input name="phone_pro" type="text" size="18" maxlength="80" value="'.(isset($_POST["phone_pro"])?$_POST["phone_pro"]:$object->phone_pro).'"></td>';
print '<td>'.$langs->trans("PhonePerso").'</td><td><input name="phone_perso" type="text" size="18" maxlength="80" value="'.(isset($_POST["phone_perso"])?$_POST["phone_perso"]:$object->phone_perso).'"></td></tr>';
print '<tr><td>'.$langs->trans("PhoneMobile").'</td><td><input name="phone_mobile" type="text" size="18" maxlength="80" value="'.(isset($_POST["phone_mobile"])?$_POST["phone_mobile"]:$object->phone_mobile).'"></td>';
print '<td>'.$langs->trans("Fax").'</td><td><input name="fax" type="text" size="18" maxlength="80" value="'.(isset($_POST["fax"])?$_POST["fax"]:$object->fax).'"></td></tr>';
// EMail
print '<tr><td>'.$langs->trans("EMail").'</td><td><input name="email" type="text" size="40" maxlength="80" value="'.(isset($_POST["email"])?$_POST["email"]:$object->email).'"></td>';
if ($conf->mailing->enabled)
@@ -624,51 +674,51 @@ else
print '<td colspan="2">&nbsp;</td>';
}
print '</tr>';
// Jabberid
print '<tr><td>Jabberid</td><td colspan="3"><input name="jabberid" type="text" size="40" maxlength="80" value="'.(isset($_POST["jabberid"])?$_POST["jabberid"]:$object->jabberid).'"></td></tr>';
// Visibility
print '<tr><td>'.$langs->trans("ContactVisibility").'</td><td colspan="3">';
$selectarray=array('0'=>$langs->trans("ContactPublic"),'1'=>$langs->trans("ContactPrivate"));
print $form->selectarray('priv',$selectarray,$object->priv,0);
print '</td></tr>';
print '<tr><td valign="top">'.$langs->trans("Note").'</td><td colspan="3">';
print '<textarea name="note" cols="70" rows="'.ROWS_3.'">';
print isset($_POST["note"])?$_POST["note"]:$object->note;
print '</textarea></td></tr>';
$object->load_ref_elements();
if ($conf->commande->enabled)
{
print '<tr><td>'.$langs->trans("ContactForOrders").'</td><td colspan="3">';
print $object->ref_commande?$object->ref_commande:$langs->trans("NoContactForAnyOrder");
print '</td></tr>';
}
if ($conf->propal->enabled)
{
print '<tr><td>'.$langs->trans("ContactForProposals").'</td><td colspan="3">';
print $object->ref_propal?$object->ref_propal:$langs->trans("NoContactForAnyProposal");
print '</td></tr>';
}
if ($conf->contrat->enabled)
{
print '<tr><td>'.$langs->trans("ContactForContracts").'</td><td colspan="3">';
print $object->ref_contrat?$object->ref_contrat:$langs->trans("NoContactForAnyContract");
print '</td></tr>';
}
if ($conf->facture->enabled)
{
print '<tr><td>'.$langs->trans("ContactForInvoices").'</td><td colspan="3">';
print $object->ref_facturation?$object->ref_facturation:$langs->trans("NoContactForAnyInvoice");
print '</td></tr>';
}
// Login Dolibarr
print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td colspan="3">';
if ($object->user_id)
@@ -679,22 +729,23 @@ else
}
else print $langs->trans("NoDolibarrAccess");
print '</td></tr>';
print '<tr><td colspan="4" align="center">';
print '</table><br>';
print '<center>';
print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
print ' &nbsp; ';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</td></tr>';
print '</table>';
print '</center>';
print "</form>";
}
}
if (GETPOST("id") && GETPOST("action") != 'edit')
{
$objsoc = new Societe($db);
/*
* Fiche en mode visualisation
*/
@@ -703,29 +754,29 @@ else
$langs->load("errors");
print '<div class="error">'.$langs->trans($msg).'</div>';
}
if ($_GET["action"] == 'create_user')
{
$login=strtolower(substr(dol_string_unaccent($object->prenom), 0, 4)) . strtolower(substr(dol_string_unaccent($object->nom), 0, 4));
// Create a form array
$formquestion=array(array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login));
$ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("CreateDolibarrLogin"),$langs->trans("ConfirmCreateContact"),"confirm_create_user",$formquestion);
if ($ret == 'html') print '<br>';
}
print '<table class="border" width="100%">';
// Ref
print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
print $form->showrefnav($object,'id');
print '</td></tr>';
// Name
print '<tr><td width="20%">'.$langs->trans("Lastname").'</td><td width="30%">'.$object->name.'</td>';
print '<td width="25%">'.$langs->trans("Firstname").'</td><td width="25%">'.$object->firstname.'</td></tr>';
print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="30%">'.$object->firstname.'</td></tr>';
// Company
print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">';
if ($object->socid > 0)
@@ -738,40 +789,40 @@ else
print $langs->trans("ContactNotLinkedToCompany");
}
print '</td></tr>';
// Civility
print '<tr><td width="15%">'.$langs->trans("UserTitle").'</td><td colspan="3">';
print $object->getCivilityLabel();
print '</td></tr>';
print '<tr><td>'.$langs->trans("PostOrFunction" ).'</td><td colspan="3">'.$object->poste.'</td>';
// Address
print '<tr><td>'.$langs->trans("Address").'</td><td colspan="3">'.nl2br($object->address).'</td></tr>';
// Zip Town
print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td colspan="3">';
print $object->cp;
if ($object->cp) print '&nbsp;';
print $object->ville.'</td></tr>';
// Country
print '<tr><td>'.$langs->trans("Country").'</td><td colspan="3">';
$img=picto_from_langcode($object->pays_code);
if ($img) print $img.' ';
print $object->pays;
print '</td></tr>';
// Department
print '<tr><td>'.$langs->trans('State').'</td><td colspan="3">'.$object->departement.'</td>';
// Phone
print '<tr><td>'.$langs->trans("PhonePro").'</td><td>'.dol_print_phone($object->phone_pro,$object->pays_code,$object->id,$object->socid,'AC_TEL').'</td>';
print '<td>'.$langs->trans("PhonePerso").'</td><td>'.dol_print_phone($object->phone_perso,$object->pays_code,$object->id,$object->socid,'AC_TEL').'</td></tr>';
print '<tr><td>'.$langs->trans("PhoneMobile").'</td><td>'.dol_print_phone($object->phone_mobile,$object->pays_code,$object->id,$object->socid,'AC_TEL').'</td>';
print '<td>'.$langs->trans("Fax").'</td><td>'.dol_print_phone($object->fax,$object->pays_code,$object->id,$object->socid,'AC_FAX').'</td></tr>';
// Email
print '<tr><td>'.$langs->trans("EMail").'</td><td>'.dol_print_email($object->email,$object->id,$object->socid,'AC_EMAIL').'</td>';
if ($conf->mailing->enabled)
@@ -785,48 +836,48 @@ else
print '<td colspan="2">&nbsp;</td>';
}
print '</tr>';
// Jabberid
print '<tr><td>Jabberid</td><td colspan="3">'.$object->jabberid.'</td></tr>';
print '<tr><td>'.$langs->trans("ContactVisibility").'</td><td colspan="3">';
print $object->LibPubPriv($object->priv);
print '</td></tr>';
print '<tr><td valign="top">'.$langs->trans("Note").'</td><td colspan="3">';
print nl2br($object->note);
print '</td></tr>';
$object->load_ref_elements();
if ($conf->commande->enabled)
{
print '<tr><td>'.$langs->trans("ContactForOrders").'</td><td colspan="3">';
print $object->ref_commande?$object->ref_commande:$langs->trans("NoContactForAnyOrder");
print '</td></tr>';
}
if ($conf->propal->enabled)
{
print '<tr><td>'.$langs->trans("ContactForProposals").'</td><td colspan="3">';
print $object->ref_propal?$object->ref_propal:$langs->trans("NoContactForAnyProposal");
print '</td></tr>';
}
if ($conf->contrat->enabled)
{
print '<tr><td>'.$langs->trans("ContactForContracts").'</td><td colspan="3">';
print $object->ref_contrat?$object->ref_contrat:$langs->trans("NoContactForAnyContract");
print '</td></tr>';
}
if ($conf->facture->enabled)
{
print '<tr><td>'.$langs->trans("ContactForInvoices").'</td><td colspan="3">';
print $object->ref_facturation?$object->ref_facturation:$langs->trans("NoContactForAnyInvoice");
print '</td></tr>';
}
print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td colspan="3">';
if ($object->user_id)
{
@@ -836,36 +887,36 @@ else
}
else print $langs->trans("NoDolibarrAccess");
print '</td></tr>';
print "</table>";
print "</div>";
// Barre d'actions
if (! $user->societe_id)
{
print '<div class="tabsAction">';
if ($user->rights->societe->contact->creer)
{
print '<a class="butAction" href="fiche.php?id='.$object->id.'&amp;action=edit">'.$langs->trans('Modify').'</a>';
}
if (! $object->user_id && $user->rights->user->user->creer)
{
print '<a class="butAction" href="fiche.php?id='.$object->id.'&amp;action=create_user">'.$langs->trans("CreateDolibarrLogin").'</a>';
}
if ($user->rights->societe->contact->supprimer)
{
print '<a class="butActionDelete" href="fiche.php?id='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
}
print "</div><br>";
}
print show_actions_todo($conf,$langs,$db,$objsoc,$object);
print show_actions_done($conf,$langs,$db,$objsoc,$object);
}
}

View File

@@ -36,6 +36,7 @@ $contactid = isset($_GET["id"])?$_GET["id"]:'';
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'contact', $contactid, 'socpeople');
/*
* Action
*/
@@ -102,8 +103,8 @@ if ($_GET["action"] == 'edit')
print '</td></tr>';
// Name
print '<tr><td>'.$langs->trans("Lastname").'</td><td>'.$contact->nom.'</td>';
print '<td>'.$langs->trans("Firstname").'</td><td width="25%">'.$contact->prenom.'</td>';
print '<tr><td width="20%">'.$langs->trans("Lastname").'</td><td width="30%">'.$contact->nom.'</td>';
print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="30%">'.$contact->prenom.'</td>';
// Company
if ($contact->socid > 0)
@@ -128,20 +129,13 @@ if ($_GET["action"] == 'edit')
// Date To Birth
print '<tr><td>'.$langs->trans("DateToBirth").'</td><td>';
$html=new Form($db);
if ($contact->birthday)
{
print $html->select_date($contact->birthday,'birthday',0,0,0,"perso");
}
else
{
print $html->select_date('','birthday',0,0,1,"perso");
}
print $html->select_date($contact->birthday,'birthday',0,0,1,"perso");
print '</td>';
print '<td colspan="2">'.$langs->trans("Alert").': ';
if ($contact->birthday_alert)
{
print '<input type="checkbox" name="birthday_alert" checked></td>';
print '<input type="checkbox" name="birthday_alert" checked="true"></td>';
}
else
{
@@ -149,8 +143,13 @@ if ($_GET["action"] == 'edit')
}
print '</tr>';
print '<tr><td colspan="4" align="center"><input class="button" type="submit" value="'.$langs->trans("Save").'"></td></tr>';
print "</table>";
print "</table><br>";
print '<center>';
print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
print ' &nbsp; ';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</center>';
print "</form>";
}
@@ -167,8 +166,8 @@ else
print '</td></tr>';
// Name
print '<tr><td>'.$langs->trans("Lastname").'</td><td>'.$contact->name.'</td>';
print '<td>'.$langs->trans("Firstname").'</td><td width="25%">'.$contact->firstname.'</td></tr>';
print '<tr><td width="20%">'.$langs->trans("Lastname").'</td><td width="30%">'.$contact->name.'</td>';
print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="30%">'.$contact->firstname.'</td></tr>';
// Company
if ($contact->socid > 0)

View File

@@ -379,11 +379,18 @@ function formatDate(date,format)
* getDateFromFormat(date_string, format_string) Purpose: This function takes a
* date string and a format string. It parses the date string with format and it
* returns the date as a javascript Date() object. If date does not match
* format, it returns 0. The format string can use the following tags: Field |
* Tags -------------+------------------------------- Year | yyyy (4 digits), yy
* (2 digits) Month | MM (2 digits) Day of Month | dd (2 digits) Hour (1-12) |
* hh (2 digits) Hour (0-23) | HH (2 digits) Minute | mm (2 digits) Second | ss
* (2 digits) Author: Laurent Destailleur Licence: GPL
* format, it returns 0. The format string can use the following tags:
* Field | Tags
* -------------+-----------------------------------
* Year | yyyy (4 digits), yy (2 digits)
* Month | MM (2 digits)
* Day of Month | dd (2 digits)
* Hour (1-12) | hh (2 digits)
* Hour (0-23) | HH (2 digits)
* Minute | mm (2 digits)
* Second | ss (2 digits)
* Author: Laurent Destailleur
* Licence: GPL
* ==================================================================
*/
function getDateFromFormat(val,format)
@@ -394,6 +401,8 @@ function getDateFromFormat(val,format)
val=val+"";
format=format+"";
if (val == '') return 0;
var now=new Date();
var year=now.getYear(); if (year.length < 4) { year=""+(year-0+1900); }
var month=now.getMonth()+1;