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';
113 public $fields = array(
114 'id_sondage' => array(
'type' =>
'varchar(16)',
'label' =>
'Idsondage',
'enabled' =>
'1',
'position' => 10,
'notnull' => 1,
'visible' => -1,),
115 'commentaires' => array(
'type' =>
'mediumtext',
'label' =>
'Comments',
'enabled' =>
'1',
'position' => 15,
'notnull' => 0,
'visible' => -1,),
116 'mail_admin' => array(
'type' =>
'varchar(128)',
'label' =>
'Mailadmin',
'enabled' =>
'1',
'position' => 20,
'notnull' => 0,
'visible' => -1,),
117 'nom_admin' => array(
'type' =>
'varchar(64)',
'label' =>
'Nomadmin',
'enabled' =>
'1',
'position' => 25,
'notnull' => 0,
'visible' => -1,),
118 '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',),
119 'titre' => array(
'type' =>
'mediumtext',
'label' =>
'Title',
'enabled' =>
'1',
'position' => 35,
'notnull' => 1,
'visible' => -1,),
120 'date_fin' => array(
'type' =>
'datetime',
'label' =>
'DateEnd',
'enabled' =>
'1',
'position' => 40,
'notnull' => 1,
'visible' => -1,),
121 'status' => array(
'type' =>
'integer',
'label' =>
'Status',
'enabled' =>
'1',
'position' => 500,
'notnull' => 0,
'visible' => -1,),
122 'format' => array(
'type' =>
'varchar(2)',
'label' =>
'Format',
'enabled' =>
'1',
'position' => 50,
'notnull' => 1,
'visible' => -1,),
123 'mailsonde' => array(
'type' =>
'integer',
'label' =>
'Mailsonde',
'enabled' =>
'1',
'position' => 55,
'notnull' => 1,
'visible' => -1,),
124 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' =>
'1',
'position' => 60,
'notnull' => 1,
'visible' => -1,),
125 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'enabled' =>
'1',
'position' => 65,
'notnull' => 1,
'visible' => -2,
'default' =>
'1',
'index' => 1,),
126 'allow_comments' => array(
'type' =>
'integer',
'label' =>
'Allowcomments',
'enabled' =>
'1',
'position' => 70,
'notnull' => 1,
'visible' => -1,),
127 'allow_spy' => array(
'type' =>
'integer',
'label' =>
'Allowspy',
'enabled' =>
'1',
'position' => 75,
'notnull' => 1,
'visible' => -1,),
128 'sujet' => array(
'type' =>
'mediumtext',
'label' =>
'Sujet',
'enabled' =>
'1',
'position' => 80,
'notnull' => 0,
'visible' => -1,),
141 public $commentaires;
156 public $fk_user_creat;
172 public $date_fin =
'';
191 public $allow_comments;
206 public $id_sondage_admin;
251 if (!$this->date_fin > 0) {
252 $this->error =
'BadValueForEndDate';
253 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
258 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"opensurvey_sondage(";
259 $sql .=
"id_sondage,";
260 $sql .=
"commentaires,";
261 $sql .=
"fk_user_creat,";
266 $sql .=
"mailsonde,";
267 $sql .=
"allow_comments,";
268 $sql .=
"allow_spy,";
271 $sql .=
") VALUES (";
272 $sql .=
"'".$this->db->escape($this->id_sondage).
"',";
274 $sql .=
" ".(int) $user->id.
",";
275 $sql .=
" '".$this->db->escape($this->title).
"',";
276 $sql .=
" '".$this->db->idate($this->date_fin).
"',";
277 $sql .=
" ".(int) $this->
status.
",";
278 $sql .=
" '".$this->db->escape($this->format).
"',";
279 $sql .=
" ".((int) $this->mailsonde).
",";
280 $sql .=
" ".((int) $this->allow_comments).
",";
281 $sql .=
" ".((int) $this->allow_spy).
",";
282 $sql .=
" '".$this->db->escape($this->sujet).
"',";
283 $sql .=
" ".((int)
$conf->entity);
288 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
289 $resql = $this->db->query($sql);
292 $this->errors[] =
"Error ".$this->db->lasterror();
295 if (!$error && !$notrigger) {
297 $result = $this->
call_trigger(
'OPENSURVEY_CREATE', $user);
306 foreach ($this->errors as $errmsg) {
307 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
308 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
310 $this->db->rollback();
326 public function fetch($id, $numsurvey =
'')
329 $sql .=
" t.id_sondage,";
330 $sql .=
" t.titre as title,";
331 $sql .=
" t.commentaires as description,";
332 $sql .=
" t.mail_admin,";
333 $sql .=
" t.nom_admin,";
334 $sql .=
" t.fk_user_creat,";
335 $sql .=
" t.date_fin,";
336 $sql .=
" t.status,";
337 $sql .=
" t.format,";
338 $sql .=
" t.mailsonde,";
339 $sql .=
" t.allow_comments,";
340 $sql .=
" t.allow_spy,";
343 $sql .=
" FROM ".MAIN_DB_PREFIX.
"opensurvey_sondage as t";
344 $sql .=
" WHERE t.id_sondage = '".$this->db->escape($id ? $id : $numsurvey).
"'";
346 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
347 $resql = $this->db->query($sql);
349 if ($this->db->num_rows($resql)) {
350 $obj = $this->db->fetch_object($resql);
352 $this->id_sondage = $obj->id_sondage;
353 $this->
ref = $this->id_sondage;
356 $this->mail_admin = $obj->mail_admin;
357 $this->nom_admin = $obj->nom_admin;
358 $this->title = $obj->title;
359 $this->date_fin = $this->db->jdate($obj->date_fin);
360 $this->
status = $obj->status;
361 $this->format = $obj->format;
362 $this->mailsonde = $obj->mailsonde;
363 $this->allow_comments = $obj->allow_comments;
364 $this->allow_spy = $obj->allow_spy;
365 $this->sujet = $obj->sujet;
366 $this->fk_user_creat = $obj->fk_user_creat;
368 $this->date_m = $this->db->jdate(!empty($obj->tms) ? $obj->tms :
"");
371 $sondage = ($id ?
'id='.$id :
'sondageid='.$numsurvey);
372 $this->error =
'Fetch no poll found for '.$sondage;
377 $this->db->free($resql);
379 $this->error =
"Error ".$this->db->lasterror();
405 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"opensurvey_sondage SET";
406 $sql .=
" id_sondage=".(isset($this->id_sondage) ?
"'".$this->db->escape($this->id_sondage).
"'" :
"null").
",";
407 $sql .=
" commentaires=".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
408 $sql .=
" mail_admin=".(isset($this->mail_admin) ?
"'".$this->db->escape($this->mail_admin).
"'" :
"null").
",";
409 $sql .=
" nom_admin=".(isset($this->nom_admin) ?
"'".$this->db->escape($this->nom_admin).
"'" :
"null").
",";
410 $sql .=
" titre=".(isset($this->title) ?
"'".$this->db->escape($this->title).
"'" :
"null").
",";
411 $sql .=
" date_fin=".(dol_strlen($this->date_fin) != 0 ?
"'".$this->db->idate($this->date_fin).
"'" :
'null').
",";
412 $sql .=
" status=".(!empty($this->
status) ? (int) $this->
status :
"null").
",";
413 $sql .=
" format=".(isset($this->format) ?
"'".$this->db->escape($this->format).
"'" :
"null").
",";
414 $sql .=
" mailsonde=".(isset($this->mailsonde) ? ((int) $this->mailsonde) :
"null").
",";
415 $sql .=
" allow_comments=".((int) $this->allow_comments).
",";
416 $sql .=
" allow_spy=".((int) $this->allow_spy);
417 $sql .=
" WHERE id_sondage='".$this->db->escape($this->id_sondage).
"'";
421 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
422 $resql = $this->db->query($sql);
425 $this->errors[] =
"Error ".$this->db->lasterror();
428 if (!$error && !$notrigger) {
430 $result = $this->
call_trigger(
'OPENSURVEY_MODIFY', $user);
439 foreach ($this->errors as $errmsg) {
440 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
441 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
443 $this->db->rollback();
459 public function delete(
User $user, $notrigger = 0, $numsondage =
'')
461 global
$conf, $langs;
464 if (empty($numsondage)) {
465 $numsondage = $this->id_sondage;
470 if (!$error && !$notrigger) {
472 $result = $this->
call_trigger(
'OPENSURVEY_DELETE', $user);
480 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"opensurvey_comments WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
481 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
482 $resql = $this->db->query($sql);
483 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"opensurvey_user_studs WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
484 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
485 $resql = $this->db->query($sql);
487 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"opensurvey_sondage";
488 $sql .=
" WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
490 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
491 $resql = $this->db->query($sql);
494 $this->errors[] =
"Error ".$this->db->lasterror();
500 foreach ($this->errors as $errmsg) {
501 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
502 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
504 $this->db->rollback();
520 global
$conf, $langs;
522 $langs->load(
'opensurvey');
525 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"ShowSurvey").
'</u>';
526 if (isset($this->
status)) {
527 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
529 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
530 if (!empty($this->date_fin)) {
531 $datas[
'expire_date'] =
'<br><b>'.$langs->trans(
'ExpireDate').
':</b> '.
dol_print_date($this->date_fin,
'day');
533 $datas[
'expire_date'] .=
img_warning($langs->trans(
"Expired"));
536 $datas[
'title'] =
'<br><b>'.$langs->trans(
'Title').
':</b> '.$this->title;
538 $datas[
'description'] =
'<br><b>'.$langs->trans(
'Description').
':</b> '.$this->description;
553 public function getNomUrl($withpicto = 0, $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
555 global
$conf, $hookmanager, $langs;
557 if (!empty(
$conf->dol_no_mouse_hover)) {
564 'objecttype' => $this->element,
566 $classfortooltip =
'classfortooltip';
569 $classfortooltip =
'classforajaxtooltip';
570 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
576 $url = DOL_URL_ROOT.
'/opensurvey/card.php?id='.$this->id;
579 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
580 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
581 $add_save_lastsearch_values = 1;
583 if ($add_save_lastsearch_values) {
584 $url .=
'&save_lastsearch_values=1';
588 if (empty($notooltip)) {
590 $label = $langs->trans(
"ShowMyObject");
591 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
593 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
594 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
596 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
599 $linkstart =
'<a href="'.$url.
'"';
600 $linkstart .= $linkclose.
'>';
603 $result .= $linkstart;
605 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
607 if ($withpicto != 2) {
608 $result .= $this->ref;
613 $hookmanager->initHooks(array($this->element .
'dao'));
614 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
615 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
617 $result = $hookmanager->resPrint;
619 $result .= $hookmanager->resPrint;
634 $this->lines = array();
636 $sql =
"SELECT id_users, nom as name, reponses";
637 $sql .=
" FROM ".MAIN_DB_PREFIX.
"opensurvey_user_studs";
638 $sql .=
" WHERE id_sondage = '".$this->db->escape($this->id_sondage).
"'";
640 $resql = $this->db->query($sql);
643 $num = $this->db->num_rows($resql);
646 $obj = $this->db->fetch_object($resql);
647 $tmp = array(
'id_users' => $obj->id_users,
'nom' => $obj->name,
'reponses' => $obj->reponses);
649 $this->lines[] = $tmp;
656 return count($this->lines);
669 $this->id_sondage =
'a12d5g';
670 $this->
description =
'Description of the specimen survey';
671 $this->mail_admin =
'email@email.com';
672 $this->nom_admin =
'surveyadmin';
673 $this->title =
'This is a specimen survey';
674 $this->date_fin =
dol_now() + 3600 * 24 * 10;
676 $this->format =
'classic';
677 $this->mailsonde = 0;
691 $sql =
'SELECT id_comment, usercomment, comment';
692 $sql .=
' FROM '.MAIN_DB_PREFIX.
'opensurvey_comments';
693 $sql .=
" WHERE id_sondage='".$this->db->escape($this->id_sondage).
"'";
694 $sql .=
" ORDER BY id_comment";
695 $resql = $this->db->query($sql);
698 $num_rows = $this->db->num_rows($resql);
701 while ($obj = $this->db->fetch_object($resql)) {
718 public function addComment($comment, $comment_user, $user_ip =
'')
721 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"opensurvey_comments (id_sondage, comment, usercomment, date_creation, ip)";
722 $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).
"'" :
'').
")";
723 $resql = $this->db->query($sql);
740 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'opensurvey_comments WHERE id_comment = '.((int) $id_comment).
' AND id_sondage = "'.$this->db->escape($this->id_sondage).
'"';
741 $resql = $this->db->query($sql);
757 $this->id_sondage = trim($this->id_sondage);
759 $this->mail_admin = trim($this->mail_admin);
760 $this->nom_admin = trim($this->nom_admin);
761 $this->title = trim($this->title);
763 $this->format = trim($this->format);
764 $this->mailsonde = ($this->mailsonde ? 1 : 0);
765 $this->allow_comments = ($this->allow_comments ? 1 : 0);
766 $this->allow_spy = ($this->allow_spy ? 1 : 0);
767 $this->sujet = trim($this->sujet);
793 global $langs,
$conf;
795 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
806 $statusType =
'status'.$status;
807 if ($status == self::STATUS_VALIDATED) {
809 $statusType =
'status1';
811 $statusType =
'status4';
814 if ($status == self::STATUS_CLOSED) {
815 $statusType =
'status6';
818 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
831 $sql =
" SELECT COUNT(id_users) as nb FROM ".MAIN_DB_PREFIX.
"opensurvey_user_studs";
832 $sql .=
" WHERE id_sondage = '".$this->db->escape($this->
ref).
"'";
834 $resql = $this->db->query($sql);
836 $obj = $this->db->fetch_object($resql);
841 $this->error = $this->db->lasterror();
842 $this->errors[] = $this->error;
860 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
868 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
869 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
870 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
872 $sql .=
' WHERE 1 = 1';
879 $this->errors[] = $errormessage;
880 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
884 if (!empty($sortfield)) {
885 $sql .= $this->db->order($sortfield, $sortorder);
887 if (!empty($limit)) {
888 $sql .= $this->db->plimit($limit, $offset);
891 $resql = $this->db->query($sql);
893 $num = $this->db->num_rows($resql);
895 while ($i < ($limit ? min($limit, $num) : $num)) {
896 $obj = $this->db->fetch_object($resql);
898 $record =
new self($this->db);
899 $record->setVarsFromFetchObj($obj);
901 $records[$record->id_sondage] = $record;
905 $this->db->free($resql);
909 $this->errors[] =
'Error '.$this->db->lasterror();
910 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_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
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).
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...