28 require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobject.class.php";
41 public $element =
'opensurvey_sondage';
46 public $table_element =
'opensurvey_sondage';
51 public $picto =
'poll';
77 public $fk_user_creat;
84 public $date_fin =
'';
109 public $allow_comments;
159 if (!$this->date_fin > 0) {
160 $this->error =
'BadValueForEndDate';
161 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
166 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"opensurvey_sondage(";
167 $sql .=
"id_sondage,";
168 $sql .=
"commentaires,";
169 $sql .=
"fk_user_creat,";
174 $sql .=
"mailsonde,";
175 $sql .=
"allow_comments,";
176 $sql .=
"allow_spy,";
179 $sql .=
") VALUES (";
180 $sql .=
"'".$this->db->escape($this->id_sondage).
"',";
182 $sql .=
" ".(int) $user->id.
",";
183 $sql .=
" '".$this->db->escape($this->title).
"',";
184 $sql .=
" '".$this->db->idate($this->date_fin).
"',";
185 $sql .=
" ".(int) $this->status.
",";
186 $sql .=
" '".$this->db->escape($this->format).
"',";
187 $sql .=
" ".((int) $this->mailsonde).
",";
188 $sql .=
" ".((int) $this->allow_comments).
",";
189 $sql .=
" ".((int) $this->allow_spy).
",";
190 $sql .=
" '".$this->db->escape($this->sujet).
"',";
191 $sql .=
" ".((int) $conf->entity);
196 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
198 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
200 if (!$error && !$notrigger) {
201 global $langs, $conf;
204 $result = $this->
call_trigger(
'OPENSURVEY_CREATE', $user);
205 if ($result < 0) $error++;
211 foreach ($this->errors as $errmsg) {
212 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
213 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
215 $this->
db->rollback();
231 public function fetch($id, $numsurvey =
'')
234 $sql .=
" t.id_sondage,";
235 $sql .=
" t.titre as title,";
236 $sql .=
" t.commentaires as description,";
237 $sql .=
" t.mail_admin,";
238 $sql .=
" t.nom_admin,";
239 $sql .=
" t.fk_user_creat,";
240 $sql .=
" t.date_fin,";
241 $sql .=
" t.status,";
242 $sql .=
" t.format,";
243 $sql .=
" t.mailsonde,";
244 $sql .=
" t.allow_comments,";
245 $sql .=
" t.allow_spy,";
248 $sql .=
" FROM ".MAIN_DB_PREFIX.
"opensurvey_sondage as t";
249 $sql .=
" WHERE t.id_sondage = '".$this->db->escape($id ? $id : $numsurvey).
"'";
251 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
257 $obj = $this->
db->fetch_object(
$resql);
259 $this->id_sondage = $obj->id_sondage;
260 $this->ref = $this->id_sondage;
263 $this->mail_admin = $obj->mail_admin;
264 $this->nom_admin = $obj->nom_admin;
265 $this->title = $obj->title;
266 $this->date_fin = $this->
db->jdate($obj->date_fin);
267 $this->status = $obj->status;
268 $this->format = $obj->format;
269 $this->mailsonde = $obj->mailsonde;
270 $this->allow_comments = $obj->allow_comments;
271 $this->allow_spy = $obj->allow_spy;
272 $this->sujet = $obj->sujet;
273 $this->fk_user_creat = $obj->fk_user_creat;
275 $this->date_m = $this->
db->jdate($obj->tls);
278 $sondage = ($id ?
'id='.$id :
'sondageid='.$numsurvey);
279 $this->error =
'Fetch no poll found for '.$sondage;
286 $this->error =
"Error ".$this->db->lasterror();
303 global $conf, $langs;
313 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"opensurvey_sondage SET";
314 $sql .=
" id_sondage=".(isset($this->id_sondage) ?
"'".$this->db->escape($this->id_sondage).
"'" :
"null").
",";
315 $sql .=
" commentaires=".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
316 $sql .=
" mail_admin=".(isset($this->mail_admin) ?
"'".$this->db->escape($this->mail_admin).
"'" :
"null").
",";
317 $sql .=
" nom_admin=".(isset($this->nom_admin) ?
"'".$this->db->escape($this->nom_admin).
"'" :
"null").
",";
318 $sql .=
" titre=".(isset($this->title) ?
"'".$this->db->escape($this->title).
"'" :
"null").
",";
319 $sql .=
" date_fin=".(dol_strlen($this->date_fin) != 0 ?
"'".$this->db->idate($this->date_fin).
"'" :
'null').
",";
320 $sql .=
" status=".(isset($this->status) ?
"'".$this->db->escape($this->status).
"'" :
"null").
",";
321 $sql .=
" format=".(isset($this->format) ?
"'".$this->db->escape($this->format).
"'" :
"null").
",";
322 $sql .=
" mailsonde=".(isset($this->mailsonde) ? $this->
db->escape($this->mailsonde) :
"null").
",";
323 $sql .=
" allow_comments=".$this->db->escape($this->allow_comments).
",";
324 $sql .=
" allow_spy=".$this->db->escape($this->allow_spy);
325 $sql .=
" WHERE id_sondage='".$this->db->escape($this->id_sondage).
"'";
329 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
333 $this->errors[] =
"Error ".$this->db->lasterror();
336 if (!$error && !$notrigger) {
338 $result = $this->
call_trigger(
'OPENSURVEY_MODIFY', $user);
339 if ($result < 0) $error++;
346 foreach ($this->errors as $errmsg)
348 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
349 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
351 $this->
db->rollback();
367 public function delete(
User $user, $notrigger = 0, $numsondage =
'')
369 global $conf, $langs;
372 if (empty($numsondage))
374 $numsondage = $this->id_sondage;
379 if (!$error && !$notrigger) {
381 $result = $this->
call_trigger(
'OPENSURVEY_DELETE', $user);
382 if ($result < 0) $error++;
388 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"opensurvey_comments WHERE id_sondage = '".$this->
db->escape($numsondage).
"'";
389 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
391 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"opensurvey_user_studs WHERE id_sondage = '".$this->
db->escape($numsondage).
"'";
392 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
395 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"opensurvey_sondage";
396 $sql .=
" WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
398 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
400 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
406 foreach ($this->errors as $errmsg)
408 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
409 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
411 $this->
db->rollback();
428 public function getNomUrl($withpicto = 0, $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
430 global $db, $conf, $langs;
431 global $dolibarr_main_authentication, $dolibarr_main_demo;
434 if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1;
438 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"ShowSurvey").
'</u>';
440 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref.
'<br>';
441 $label .=
'<b>'.$langs->trans(
'Title').
':</b> '.$this->title.
'<br>';
443 $url = DOL_URL_ROOT.
'/opensurvey/card.php?id='.$this->id;
446 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
447 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
448 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
451 if (empty($notooltip))
453 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
455 $label = $langs->trans(
"ShowMyObject");
456 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
458 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
459 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
461 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
464 $linkstart =
'<a href="'.$url.
'"';
465 $linkstart .= $linkclose.
'>';
468 $result .= $linkstart;
469 if ($withpicto) $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
470 if ($withpicto != 2) $result .= $this->ref;
487 $sql =
"SELECT id_users, nom as name, reponses FROM ".MAIN_DB_PREFIX.
"opensurvey_user_studs";
488 $sql .=
" WHERE id_sondage = '".$this->db->escape($this->id_sondage).
"'";
497 $obj = $this->
db->fetch_object(
$resql);
498 $tmp = array(
'id_users'=>$obj->id_users,
'nom'=>$obj->name,
'reponses'=>$obj->reponses);
507 return count($this->lines);
520 $this->id_sondage =
'a12d5g';
521 $this->
description =
'Description of the specimen survey';
522 $this->mail_admin =
'email@email.com';
523 $this->nom_admin =
'surveyadmin';
524 $this->title =
'This is a specimen survey';
525 $this->date_fin =
dol_now() + 3600 * 24 * 10;
527 $this->format =
'classic';
528 $this->mailsonde = 0;
540 $sql =
'SELECT id_comment, usercomment, comment';
541 $sql .=
' FROM '.MAIN_DB_PREFIX.
'opensurvey_comments';
542 $sql .=
" WHERE id_sondage='".$this->db->escape($this->id_sondage).
"'";
543 $sql .=
" ORDER BY id_comment";
548 $num_rows = $this->
db->num_rows(
$resql);
552 while ($obj = $this->
db->fetch_object(
$resql))
571 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"opensurvey_comments (id_sondage, comment, usercomment)";
572 $sql .=
" VALUES ('".$this->db->escape($this->id_sondage).
"','".$this->
db->escape($comment).
"','".$this->
db->escape($comment_user).
"')";
590 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'opensurvey_comments WHERE id_comment = '.$id_comment.
' AND id_sondage = "'.$this->
db->escape($this->id_sondage).
'"';
607 $this->id_sondage = trim($this->id_sondage);
609 $this->mail_admin = trim($this->mail_admin);
610 $this->nom_admin = trim($this->nom_admin);
611 $this->title = trim($this->title);
612 $this->status = (int) $this->status;
613 $this->format = trim($this->format);
614 $this->mailsonde = ($this->mailsonde ? 1 : 0);
615 $this->allow_comments = ($this->allow_comments ? 1 : 0);
616 $this->allow_spy = ($this->allow_spy ? 1 : 0);
617 $this->sujet = trim($this->sujet);
629 return $this->
LibStatut($this->status, $mode);
643 global $langs, $conf;
645 if (empty($this->labelStatus) || empty($this->labelStatusShort))
649 $this->labelStatus[self::STATUS_DRAFT] = $langs->trans(
'Draft');
650 $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans(
'Opened');
651 $this->labelStatus[self::STATUS_CLOSED] = $langs->trans(
'Closed');
652 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans(
'Draft');
653 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans(
'Opened');
654 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->trans(
'Closed');
657 $statusType =
'status'.$status;
658 if ($status == self::STATUS_VALIDATED) {
659 if (0) $statusType =
'status1';
660 else $statusType =
'status4';
662 if ($status == self::STATUS_CLOSED) $statusType =
'status6';
664 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
LibStatut($status, $mode)
Return label of status.
create(User $user, $notrigger=0)
Create object into database.
fetch_lines()
Return array of lines.
const STATUS_DRAFT
Draft status (not used)
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
update(User $user, $notrigger=0)
Update object into database.
fetch($id, $numsurvey= '')
Load object in memory from the database.
dol_now($mode= 'auto')
Return date for now.
cleanParameters()
Cleans all the class variables before doing an update or an insert.
Class to manage Dolibarr users.
deleteComment($id_comment)
Deletes a comment of the poll.
__construct($db)
Constructor.
$conf db
API class for accounts.
const STATUS_CLOSED
Closed.
getNomUrl($withpicto=0, $notooltip=0, $morecss= '', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
getComments()
Returns all comments for the current opensurvey poll.
getLibStatut($mode)
Return status label of Order.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
const STATUS_VALIDATED
Validated/Opened status.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
addComment($comment, $comment_user)
Adds a comment to the poll.
Put here description of your class.
print $_SERVER["PHP_SELF"]
Edit parameters.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
call_trigger($triggerName, $user)
Call trigger based on this instance.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)