29require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobject.class.php";
40 public $element =
'opensurvey_sondage';
45 public $table_element =
'opensurvey_sondage';
50 public $table_rowid =
'id_sondage';
55 public $picto =
'poll';
118 public $fields = array(
119 'id_sondage' => array(
'type' =>
'varchar(16)',
'label' =>
'Idsondage',
'enabled' =>
'1',
'position' => 10,
'notnull' => 1,
'visible' => -1,),
120 'commentaires' => array(
'type' =>
'mediumtext',
'label' =>
'Comments',
'enabled' =>
'1',
'position' => 15,
'notnull' => 0,
'visible' => -1,),
121 'mail_admin' => array(
'type' =>
'varchar(128)',
'label' =>
'Mailadmin',
'enabled' =>
'1',
'position' => 20,
'notnull' => 0,
'visible' => -1,),
122 'nom_admin' => array(
'type' =>
'varchar(64)',
'label' =>
'Nomadmin',
'enabled' =>
'1',
'position' => 25,
'notnull' => 0,
'visible' => -1,),
123 'fk_user_creat' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' =>
'1',
'position' => 30,
'notnull' => 1,
'visible' => -2,
'css' =>
'maxwidth500 widthcentpercentminusxx',
'csslist' =>
'tdoverflowmax150',),
124 'titre' => array(
'type' =>
'mediumtext',
'label' =>
'Title',
'enabled' =>
'1',
'position' => 35,
'notnull' => 1,
'visible' => -1,),
125 'date_fin' => array(
'type' =>
'datetime',
'label' =>
'DateEnd',
'enabled' =>
'1',
'position' => 40,
'notnull' => 1,
'visible' => -1,),
126 'status' => array(
'type' =>
'integer',
'label' =>
'Status',
'enabled' =>
'1',
'position' => 500,
'notnull' => 0,
'visible' => -1,),
127 'format' => array(
'type' =>
'varchar(2)',
'label' =>
'Format',
'enabled' =>
'1',
'position' => 50,
'notnull' => 1,
'visible' => -1,),
128 'mailsonde' => array(
'type' =>
'integer',
'label' =>
'Mailsonde',
'enabled' =>
'1',
'position' => 55,
'notnull' => 1,
'visible' => -1,),
129 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' =>
'1',
'position' => 60,
'notnull' => 1,
'visible' => -1,),
130 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'enabled' =>
'1',
'position' => 65,
'notnull' => 1,
'visible' => -2,
'default' =>
'1',
'index' => 1,),
131 'allow_comments' => array(
'type' =>
'integer',
'label' =>
'Allowcomments',
'enabled' =>
'1',
'position' => 70,
'notnull' => 1,
'visible' => -1,),
132 'allow_spy' => array(
'type' =>
'integer',
'label' =>
'Allowspy',
'enabled' =>
'1',
'position' => 75,
'notnull' => 1,
'visible' => -1,),
133 'sujet' => array(
'type' =>
'mediumtext',
'label' =>
'Sujet',
'enabled' =>
'1',
'position' => 80,
'notnull' => 0,
'visible' => -1,),
146 public $commentaires;
161 public $fk_user_creat;
177 public $date_fin =
'';
197 public $allow_comments;
212 public $id_sondage_admin;
257 if (!$this->date_fin > 0) {
258 $this->error =
'BadValueForEndDate';
259 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
264 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"opensurvey_sondage(";
265 $sql .=
"id_sondage,";
266 $sql .=
"commentaires,";
267 $sql .=
"fk_user_creat,";
272 $sql .=
"mailsonde,";
273 $sql .=
"allow_comments,";
274 $sql .=
"allow_spy,";
277 $sql .=
") VALUES (";
278 $sql .=
"'".$this->db->escape($this->id_sondage).
"',";
280 $sql .=
" ".(int) $user->id.
",";
281 $sql .=
" '".$this->db->escape((
string) $this->title).
"',";
282 $sql .=
" '".$this->db->idate($this->date_fin).
"',";
283 $sql .=
" ".(int) $this->
status.
",";
284 $sql .=
" '".$this->db->escape((
string) $this->format).
"',";
285 $sql .=
" ".((int) $this->mailsonde).
",";
286 $sql .=
" ".((int) $this->allow_comments).
",";
287 $sql .=
" ".((int) $this->allow_spy).
",";
288 $sql .=
" '".$this->db->escape($this->sujet).
"',";
289 $sql .=
" ".((int) $conf->entity);
294 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
295 $resql = $this->db->query($sql);
298 $this->errors[] =
"Error ".$this->db->lasterror();
301 if (!$error && !$notrigger) {
303 $result = $this->call_trigger(
'OPENSURVEY_CREATE', $user);
312 foreach ($this->errors as $errmsg) {
313 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
314 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
316 $this->db->rollback();
332 public function fetch($id, $numsurvey =
'')
335 $sql .=
" t.id_sondage,";
336 $sql .=
" t.titre as title,";
337 $sql .=
" t.commentaires as description,";
338 $sql .=
" t.mail_admin,";
339 $sql .=
" t.nom_admin,";
340 $sql .=
" t.fk_user_creat,";
341 $sql .=
" t.date_fin,";
342 $sql .=
" t.status,";
343 $sql .=
" t.format,";
344 $sql .=
" t.mailsonde,";
345 $sql .=
" t.allow_comments,";
346 $sql .=
" t.allow_spy,";
349 $sql .=
" FROM ".MAIN_DB_PREFIX.
"opensurvey_sondage as t";
350 $sql .=
" WHERE t.id_sondage = '".$this->db->escape($id ? $id : $numsurvey).
"'";
352 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
353 $resql = $this->db->query($sql);
355 if ($this->db->num_rows($resql)) {
356 $obj = $this->db->fetch_object($resql);
358 $this->id_sondage = $obj->id_sondage;
359 $this->
ref = $this->id_sondage;
362 $this->mail_admin = $obj->mail_admin;
363 $this->nom_admin = $obj->nom_admin;
364 $this->title = $obj->title;
365 $this->date_fin = $this->db->jdate($obj->date_fin);
366 $this->
status = $obj->status;
367 $this->format = $obj->format;
368 $this->mailsonde = $obj->mailsonde;
369 $this->allow_comments = $obj->allow_comments;
370 $this->allow_spy = $obj->allow_spy;
371 $this->sujet = $obj->sujet;
372 $this->fk_user_creat = $obj->fk_user_creat;
374 $this->date_m = $this->db->jdate(!empty($obj->tms) ? $obj->tms :
"");
377 $sondage = ($id ?
'id='.$id :
'sondageid='.$numsurvey);
378 $this->error =
'Fetch no poll found for '.$sondage;
383 $this->db->free($resql);
385 $this->error =
"Error ".$this->db->lasterror();
411 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"opensurvey_sondage SET";
412 $sql .=
" id_sondage=".(isset($this->id_sondage) ?
"'".$this->db->escape($this->id_sondage).
"'" :
"null").
",";
413 $sql .=
" commentaires=".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
414 $sql .=
" mail_admin=".(isset($this->mail_admin) ?
"'".$this->db->escape($this->mail_admin).
"'" :
"null").
",";
415 $sql .=
" nom_admin=".(isset($this->nom_admin) ?
"'".$this->db->escape($this->nom_admin).
"'" :
"null").
",";
416 $sql .=
" titre=".(isset($this->title) ?
"'".$this->db->escape($this->title).
"'" :
"null").
",";
417 $sql .=
" date_fin=".(dol_strlen($this->date_fin) != 0 ?
"'".$this->db->idate($this->date_fin).
"'" :
'null').
",";
418 $sql .=
" status=".(!empty($this->
status) ? (int) $this->
status :
"null").
",";
419 $sql .=
" format=".(isset($this->format) ?
"'".$this->db->escape($this->format).
"'" :
"null").
",";
420 $sql .=
" mailsonde=".(isset($this->mailsonde) ? ((int) $this->mailsonde) :
"null").
",";
421 $sql .=
" allow_comments=".((int) $this->allow_comments).
",";
422 $sql .=
" allow_spy=".((int) $this->allow_spy);
423 $sql .=
" WHERE id_sondage='".$this->db->escape($this->id_sondage).
"'";
427 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
428 $resql = $this->db->query($sql);
431 $this->errors[] =
"Error ".$this->db->lasterror();
434 if (!$error && !$notrigger) {
436 $result = $this->call_trigger(
'OPENSURVEY_MODIFY', $user);
445 foreach ($this->errors as $errmsg) {
446 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
447 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
449 $this->db->rollback();
465 public function delete(
User $user, $notrigger = 0, $numsondage =
'')
467 global $conf, $langs;
470 if (empty($numsondage)) {
471 $numsondage = $this->id_sondage;
476 if (!$error && !$notrigger) {
478 $result = $this->call_trigger(
'OPENSURVEY_DELETE', $user);
486 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"opensurvey_comments WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
487 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
488 $resql = $this->db->query($sql);
489 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"opensurvey_user_studs WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
490 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
491 $resql = $this->db->query($sql);
493 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"opensurvey_sondage";
494 $sql .=
" WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
496 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
497 $resql = $this->db->query($sql);
500 $this->errors[] =
"Error ".$this->db->lasterror();
506 foreach ($this->errors as $errmsg) {
507 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
508 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
510 $this->db->rollback();
526 global $conf, $langs;
528 $langs->load(
'opensurvey');
531 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"ShowSurvey").
'</u>';
532 if (isset($this->
status)) {
533 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
535 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
536 if (!empty($this->date_fin)) {
537 $datas[
'expire_date'] =
'<br><b>'.$langs->trans(
'ExpireDate').
':</b> '.
dol_print_date($this->date_fin,
'day');
539 $datas[
'expire_date'] .=
img_warning($langs->trans(
"Expired"));
542 $datas[
'title'] =
'<br><b>'.$langs->trans(
'Title').
':</b> '.$this->title;
544 $datas[
'description'] =
'<br><b>'.$langs->trans(
'Description').
':</b> '.$this->description;
559 public function getNomUrl($withpicto = 0, $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
561 global $conf, $hookmanager, $langs;
563 if (!empty($conf->dol_no_mouse_hover)) {
570 'objecttype' => $this->element,
572 $classfortooltip =
'classfortooltip';
575 $classfortooltip =
'classforajaxtooltip';
576 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
582 $url = DOL_URL_ROOT.
'/opensurvey/card.php?id='.$this->id;
585 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
586 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
587 $add_save_lastsearch_values = 1;
589 if ($add_save_lastsearch_values) {
590 $url .=
'&save_lastsearch_values=1';
594 if (empty($notooltip)) {
596 $label = $langs->trans(
"ShowMyObject");
597 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
599 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
600 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
602 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
605 $linkstart =
'<a href="'.$url.
'"';
606 $linkstart .= $linkclose.
'>';
609 $result .= $linkstart;
611 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
613 if ($withpicto != 2) {
614 $result .= $this->ref;
619 $hookmanager->initHooks(array($this->element .
'dao'));
620 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
621 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
623 $result = $hookmanager->resPrint;
625 $result .= $hookmanager->resPrint;
640 $this->lines = array();
642 $sql =
"SELECT id_users, nom as name, reponses";
643 $sql .=
" FROM ".MAIN_DB_PREFIX.
"opensurvey_user_studs";
644 $sql .=
" WHERE id_sondage = '".$this->db->escape($this->id_sondage).
"'";
646 $resql = $this->db->query($sql);
649 $num = $this->db->num_rows($resql);
652 $obj = $this->db->fetch_object($resql);
653 $tmp = array(
'id_users' => $obj->id_users,
'nom' => $obj->name,
'reponses' => $obj->reponses);
655 $this->lines[] = $tmp;
662 return count($this->lines);
675 $this->id_sondage =
'a12d5g';
676 $this->
description =
'Description of the specimen survey';
677 $this->mail_admin =
'email@email.com';
678 $this->nom_admin =
'surveyadmin';
679 $this->title =
'This is a specimen survey';
680 $this->date_fin =
dol_now() + 3600 * 24 * 10;
682 $this->format =
'classic';
683 $this->mailsonde = 0;
697 $sql =
'SELECT id_comment, usercomment, comment';
698 $sql .=
' FROM '.MAIN_DB_PREFIX.
'opensurvey_comments';
699 $sql .=
" WHERE id_sondage='".$this->db->escape($this->id_sondage).
"'";
700 $sql .=
" ORDER BY id_comment";
701 $resql = $this->db->query($sql);
704 $num_rows = $this->db->num_rows($resql);
707 while ($obj = $this->db->fetch_object($resql)) {
724 public function addComment($comment, $comment_user, $user_ip =
'')
727 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"opensurvey_comments (id_sondage, comment, usercomment, date_creation, ip)";
728 $sql .=
" VALUES ('".$this->db->escape($this->id_sondage).
"','".$this->db->escape($comment).
"','".$this->db->escape($comment_user).
"','".$this->db->idate($now).
"'".($user_ip ?
",'".$this->db->escape($user_ip).
"'" :
'').
")";
729 $resql = $this->db->query($sql);
746 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'opensurvey_comments WHERE id_comment = '.((int) $id_comment).
' AND id_sondage = "'.$this->db->escape($this->id_sondage).
'"';
747 $resql = $this->db->query($sql);
763 $this->id_sondage = trim($this->id_sondage);
765 $this->mail_admin = trim($this->mail_admin);
766 $this->nom_admin = trim($this->nom_admin);
767 $this->title = trim($this->title);
769 $this->format = trim($this->format);
770 $this->mailsonde = ($this->mailsonde ? 1 : 0);
771 $this->allow_comments = ($this->allow_comments ? 1 : 0);
772 $this->allow_spy = ($this->allow_spy ? 1 : 0);
773 $this->sujet = trim($this->sujet);
799 global $langs, $conf;
801 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
812 $statusType =
'status'.$status;
813 if ($status == self::STATUS_VALIDATED) {
814 $statusType =
'status4';
816 if ($status == self::STATUS_CLOSED) {
817 $statusType =
'status6';
820 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
833 $sql =
" SELECT COUNT(id_users) as nb FROM ".MAIN_DB_PREFIX.
"opensurvey_user_studs";
834 $sql .=
" WHERE id_sondage = '".$this->db->escape($this->
ref).
"'";
836 $resql = $this->db->query($sql);
838 $obj = $this->db->fetch_object($resql);
843 $this->error = $this->db->lasterror();
844 $this->errors[] = $this->error;
862 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
870 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
871 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
872 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
874 $sql .=
' WHERE 1 = 1';
881 $this->errors[] = $errormessage;
882 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
886 if (!empty($sortfield)) {
887 $sql .= $this->db->order($sortfield, $sortorder);
889 if (!empty($limit)) {
890 $sql .= $this->db->plimit($limit, $offset);
893 $resql = $this->db->query($sql);
895 $num = $this->db->num_rows($resql);
897 while ($i < ($limit ? min($limit, $num) : $num)) {
898 $obj = $this->db->fetch_object($resql);
900 $record =
new self($this->db);
901 $record->setVarsFromFetchObj($obj);
903 $records[$record->id_sondage] = $record;
907 $this->db->free($resql);
911 $this->errors[] =
'Error '.$this->db->lasterror();
912 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
Parent class of all other business classes (invoices, contracts, proposals, orders,...
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
Put here description of your class.
__construct($db)
Constructor.
cleanParameters()
Cleans all the class variables before doing an update or an insert.
getLibStatut($mode)
Return status label of Order.
deleteComment($id_comment)
Deletes a comment of the poll.
create(User $user, $notrigger=0)
Create object into database.
fetch($id, $numsurvey='')
Load object in memory from the database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
const STATUS_VALIDATED
Validated/Opened status.
update(User $user, $notrigger=0)
Update object into database.
const STATUS_CLOSED
Closed.
getTooltipContentArray($params)
getTooltipContentArray
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
getComments()
Returns all comments for the current opensurvey poll.
fetch_lines()
Return array of lines.
const STATUS_DRAFT
Draft status (not used)
getNomUrl($withpicto=0, $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
countVotes()
Return number of votes done for this survey.
LibStatut($status, $mode)
Return label of status.
addComment($comment, $comment_user, $user_ip='')
Adds a comment to the poll.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.