29require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobject.class.php";
40 public $element =
'opensurvey_sondage';
45 public $table_element =
'opensurvey_sondage';
50 public $picto =
'poll';
106 public $fields = array(
107 'id_sondage' => array(
'type' =>
'varchar(16)',
'label' =>
'Idsondage',
'enabled' =>
'1',
'position' => 10,
'notnull' => 1,
'visible' => -1,),
108 'commentaires' => array(
'type' =>
'mediumtext',
'label' =>
'Comments',
'enabled' =>
'1',
'position' => 15,
'notnull' => 0,
'visible' => -1,),
109 'mail_admin' => array(
'type' =>
'varchar(128)',
'label' =>
'Mailadmin',
'enabled' =>
'1',
'position' => 20,
'notnull' => 0,
'visible' => -1,),
110 'nom_admin' => array(
'type' =>
'varchar(64)',
'label' =>
'Nomadmin',
'enabled' =>
'1',
'position' => 25,
'notnull' => 0,
'visible' => -1,),
111 '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',),
112 'titre' => array(
'type' =>
'mediumtext',
'label' =>
'Title',
'enabled' =>
'1',
'position' => 35,
'notnull' => 1,
'visible' => -1,),
113 'date_fin' => array(
'type' =>
'datetime',
'label' =>
'DateEnd',
'enabled' =>
'1',
'position' => 40,
'notnull' => 1,
'visible' => -1,),
114 'status' => array(
'type' =>
'integer',
'label' =>
'Status',
'enabled' =>
'1',
'position' => 500,
'notnull' => 0,
'visible' => -1,),
115 'format' => array(
'type' =>
'varchar(2)',
'label' =>
'Format',
'enabled' =>
'1',
'position' => 50,
'notnull' => 1,
'visible' => -1,),
116 'mailsonde' => array(
'type' =>
'integer',
'label' =>
'Mailsonde',
'enabled' =>
'1',
'position' => 55,
'notnull' => 1,
'visible' => -1,),
117 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' =>
'1',
'position' => 60,
'notnull' => 1,
'visible' => -1,),
118 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'enabled' =>
'1',
'position' => 65,
'notnull' => 1,
'visible' => -2,
'default' =>
'1',
'index' => 1,),
119 'allow_comments' => array(
'type' =>
'integer',
'label' =>
'Allowcomments',
'enabled' =>
'1',
'position' => 70,
'notnull' => 1,
'visible' => -1,),
120 'allow_spy' => array(
'type' =>
'integer',
'label' =>
'Allowspy',
'enabled' =>
'1',
'position' => 75,
'notnull' => 1,
'visible' => -1,),
121 'sujet' => array(
'type' =>
'mediumtext',
'label' =>
'Sujet',
'enabled' =>
'1',
'position' => 80,
'notnull' => 0,
'visible' => -1,),
122 'id_sondage_admin' => array(
'type' =>
'char(24)',
'label' =>
'Idsondageadmin',
'enabled' =>
'1',
'position' => 85,
'notnull' => 0,
'visible' => -1,),
134 public $commentaires;
149 public $fk_user_creat;
159 public $date_fin =
'';
175 public $allow_comments;
190 public $id_sondage_admin;
235 if (!$this->date_fin > 0) {
236 $this->error =
'BadValueForEndDate';
237 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
242 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"opensurvey_sondage(";
243 $sql .=
"id_sondage,";
244 $sql .=
"commentaires,";
245 $sql .=
"fk_user_creat,";
250 $sql .=
"mailsonde,";
251 $sql .=
"allow_comments,";
252 $sql .=
"allow_spy,";
255 $sql .=
") VALUES (";
256 $sql .=
"'".$this->db->escape($this->id_sondage).
"',";
258 $sql .=
" ".(int) $user->id.
",";
259 $sql .=
" '".$this->db->escape($this->title).
"',";
260 $sql .=
" '".$this->db->idate($this->date_fin).
"',";
261 $sql .=
" ".(int) $this->
status.
",";
262 $sql .=
" '".$this->db->escape($this->format).
"',";
263 $sql .=
" ".((int) $this->mailsonde).
",";
264 $sql .=
" ".((int) $this->allow_comments).
",";
265 $sql .=
" ".((int) $this->allow_spy).
",";
266 $sql .=
" '".$this->db->escape($this->sujet).
"',";
267 $sql .=
" ".((int) $conf->entity);
272 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
273 $resql = $this->db->query($sql);
276 $this->errors[] =
"Error ".$this->db->lasterror();
279 if (!$error && !$notrigger) {
281 $result = $this->
call_trigger(
'OPENSURVEY_CREATE', $user);
290 foreach ($this->errors as $errmsg) {
291 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
292 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
294 $this->db->rollback();
310 public function fetch($id, $numsurvey =
'')
313 $sql .=
" t.id_sondage,";
314 $sql .=
" t.titre as title,";
315 $sql .=
" t.commentaires as description,";
316 $sql .=
" t.mail_admin,";
317 $sql .=
" t.nom_admin,";
318 $sql .=
" t.fk_user_creat,";
319 $sql .=
" t.date_fin,";
320 $sql .=
" t.status,";
321 $sql .=
" t.format,";
322 $sql .=
" t.mailsonde,";
323 $sql .=
" t.allow_comments,";
324 $sql .=
" t.allow_spy,";
327 $sql .=
" FROM ".MAIN_DB_PREFIX.
"opensurvey_sondage as t";
328 $sql .=
" WHERE t.id_sondage = '".$this->db->escape($id ? $id : $numsurvey).
"'";
330 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
331 $resql = $this->db->query($sql);
333 if ($this->db->num_rows($resql)) {
334 $obj = $this->db->fetch_object($resql);
336 $this->id_sondage = $obj->id_sondage;
337 $this->
ref = $this->id_sondage;
340 $this->mail_admin = $obj->mail_admin;
341 $this->nom_admin = $obj->nom_admin;
342 $this->title = $obj->title;
343 $this->date_fin = $this->db->jdate($obj->date_fin);
344 $this->
status = $obj->status;
345 $this->format = $obj->format;
346 $this->mailsonde = $obj->mailsonde;
347 $this->allow_comments = $obj->allow_comments;
348 $this->allow_spy = $obj->allow_spy;
349 $this->sujet = $obj->sujet;
350 $this->fk_user_creat = $obj->fk_user_creat;
352 $this->date_m = $this->db->jdate(!empty($obj->tms) ? $obj->tms :
"");
355 $sondage = ($id ?
'id='.$id :
'sondageid='.$numsurvey);
356 $this->error =
'Fetch no poll found for '.$sondage;
361 $this->db->free($resql);
363 $this->error =
"Error ".$this->db->lasterror();
389 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"opensurvey_sondage SET";
390 $sql .=
" id_sondage=".(isset($this->id_sondage) ?
"'".$this->db->escape($this->id_sondage).
"'" :
"null").
",";
391 $sql .=
" commentaires=".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
392 $sql .=
" mail_admin=".(isset($this->mail_admin) ?
"'".$this->db->escape($this->mail_admin).
"'" :
"null").
",";
393 $sql .=
" nom_admin=".(isset($this->nom_admin) ?
"'".$this->db->escape($this->nom_admin).
"'" :
"null").
",";
394 $sql .=
" titre=".(isset($this->title) ?
"'".$this->db->escape($this->title).
"'" :
"null").
",";
395 $sql .=
" date_fin=".(dol_strlen($this->date_fin) != 0 ?
"'".$this->db->idate($this->date_fin).
"'" :
'null').
",";
396 $sql .=
" status=".(isset($this->
status) ?
"'".$this->db->escape($this->
status).
"'" :
"null").
",";
397 $sql .=
" format=".(isset($this->format) ?
"'".$this->db->escape($this->format).
"'" :
"null").
",";
398 $sql .=
" mailsonde=".(isset($this->mailsonde) ? ((int) $this->mailsonde) :
"null").
",";
399 $sql .=
" allow_comments=".((int) $this->allow_comments).
",";
400 $sql .=
" allow_spy=".((int) $this->allow_spy);
401 $sql .=
" WHERE id_sondage='".$this->db->escape($this->id_sondage).
"'";
405 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
406 $resql = $this->db->query($sql);
409 $this->errors[] =
"Error ".$this->db->lasterror();
412 if (!$error && !$notrigger) {
414 $result = $this->
call_trigger(
'OPENSURVEY_MODIFY', $user);
423 foreach ($this->errors as $errmsg) {
424 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
425 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
427 $this->db->rollback();
443 public function delete(
User $user, $notrigger = 0, $numsondage =
'')
445 global $conf, $langs;
448 if (empty($numsondage)) {
449 $numsondage = $this->id_sondage;
454 if (!$error && !$notrigger) {
456 $result = $this->
call_trigger(
'OPENSURVEY_DELETE', $user);
464 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"opensurvey_comments WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
465 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
466 $resql = $this->db->query($sql);
467 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"opensurvey_user_studs WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
468 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
469 $resql = $this->db->query($sql);
471 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"opensurvey_sondage";
472 $sql .=
" WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
474 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
475 $resql = $this->db->query($sql);
478 $this->errors[] =
"Error ".$this->db->lasterror();
484 foreach ($this->errors as $errmsg) {
485 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
486 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
488 $this->db->rollback();
504 global $conf, $langs;
506 $langs->load(
'opensurvey');
509 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"ShowSurvey").
'</u>';
510 if (isset($this->
status)) {
511 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
513 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
514 if (!empty($this->date_fin)) {
515 $datas[
'expire_date'] =
'<br><b>'.$langs->trans(
'ExpireDate').
':</b> '.
dol_print_date($this->date_fin,
'day');
517 $datas[
'expire_date'] .=
img_warning($langs->trans(
"Expired"));
520 $datas[
'title'] =
'<br><b>'.$langs->trans(
'Title').
':</b> '.$this->title;
522 $datas[
'description'] =
'<br><b>'.$langs->trans(
'Description').
':</b> '.$this->description;
537 public function getNomUrl($withpicto = 0, $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
539 global $conf, $hookmanager, $langs;
541 if (!empty($conf->dol_no_mouse_hover)) {
548 'objecttype' => $this->element,
550 $classfortooltip =
'classfortooltip';
553 $classfortooltip =
'classforajaxtooltip';
554 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
560 $url = DOL_URL_ROOT.
'/opensurvey/card.php?id='.$this->id;
563 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
564 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
565 $add_save_lastsearch_values = 1;
567 if ($add_save_lastsearch_values) {
568 $url .=
'&save_lastsearch_values=1';
572 if (empty($notooltip)) {
574 $label = $langs->trans(
"ShowMyObject");
575 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
577 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
578 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
580 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
583 $linkstart =
'<a href="'.$url.
'"';
584 $linkstart .= $linkclose.
'>';
587 $result .= $linkstart;
589 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
591 if ($withpicto != 2) {
592 $result .= $this->ref;
597 $hookmanager->initHooks(array($this->element .
'dao'));
598 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
599 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
601 $result = $hookmanager->resPrint;
603 $result .= $hookmanager->resPrint;
618 $this->lines = array();
620 $sql =
"SELECT id_users, nom as name, reponses";
621 $sql .=
" FROM ".MAIN_DB_PREFIX.
"opensurvey_user_studs";
622 $sql .=
" WHERE id_sondage = '".$this->db->escape($this->id_sondage).
"'";
624 $resql = $this->db->query($sql);
627 $num = $this->db->num_rows($resql);
630 $obj = $this->db->fetch_object($resql);
631 $tmp = array(
'id_users' => $obj->id_users,
'nom' => $obj->name,
'reponses' => $obj->reponses);
633 $this->lines[] = $tmp;
640 return count($this->lines);
653 $this->id_sondage =
'a12d5g';
654 $this->
description =
'Description of the specimen survey';
655 $this->mail_admin =
'email@email.com';
656 $this->nom_admin =
'surveyadmin';
657 $this->title =
'This is a specimen survey';
658 $this->date_fin =
dol_now() + 3600 * 24 * 10;
660 $this->format =
'classic';
661 $this->mailsonde = 0;
675 $sql =
'SELECT id_comment, usercomment, comment';
676 $sql .=
' FROM '.MAIN_DB_PREFIX.
'opensurvey_comments';
677 $sql .=
" WHERE id_sondage='".$this->db->escape($this->id_sondage).
"'";
678 $sql .=
" ORDER BY id_comment";
679 $resql = $this->db->query($sql);
682 $num_rows = $this->db->num_rows($resql);
685 while ($obj = $this->db->fetch_object($resql)) {
702 public function addComment($comment, $comment_user, $user_ip =
'')
705 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"opensurvey_comments (id_sondage, comment, usercomment, date_creation, ip)";
706 $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).
"'" :
'').
")";
707 $resql = $this->db->query($sql);
724 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'opensurvey_comments WHERE id_comment = '.((int) $id_comment).
' AND id_sondage = "'.$this->db->escape($this->id_sondage).
'"';
725 $resql = $this->db->query($sql);
741 $this->id_sondage = trim($this->id_sondage);
743 $this->mail_admin = trim($this->mail_admin);
744 $this->nom_admin = trim($this->nom_admin);
745 $this->title = trim($this->title);
747 $this->format = trim($this->format);
748 $this->mailsonde = ($this->mailsonde ? 1 : 0);
749 $this->allow_comments = ($this->allow_comments ? 1 : 0);
750 $this->allow_spy = ($this->allow_spy ? 1 : 0);
751 $this->sujet = trim($this->sujet);
777 global $langs, $conf;
779 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
790 $statusType =
'status'.$status;
791 if ($status == self::STATUS_VALIDATED) {
793 $statusType =
'status1';
795 $statusType =
'status4';
798 if ($status == self::STATUS_CLOSED) {
799 $statusType =
'status6';
802 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
815 $sql =
" SELECT COUNT(id_users) as nb FROM ".MAIN_DB_PREFIX.
"opensurvey_user_studs";
816 $sql .=
" WHERE id_sondage = '".$this->db->escape($this->
ref).
"'";
818 $resql = $this->db->query($sql);
820 $obj = $this->db->fetch_object($resql);
825 $this->error = $this->db->lasterror();
826 $this->errors[] = $this->error;
844 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
852 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
853 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
854 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
856 $sql .=
' WHERE 1 = 1';
863 $this->errors[] = $errormessage;
864 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
868 if (!empty($sortfield)) {
869 $sql .= $this->db->order($sortfield, $sortorder);
871 if (!empty($limit)) {
872 $sql .= $this->db->plimit($limit, $offset);
875 $resql = $this->db->query($sql);
877 $num = $this->db->num_rows($resql);
879 while ($i < ($limit ? min($limit, $num) : $num)) {
880 $obj = $this->db->fetch_object($resql);
882 $record =
new self($this->db);
883 $record->setVarsFromFetchObj($obj);
885 $records[$record->id_sondage] = $record;
889 $this->db->free($resql);
893 $this->errors[] =
'Error '.$this->db->lasterror();
894 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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
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.