28require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobject.class.php";
39 public $element =
'opensurvey_sondage';
44 public $table_element =
'opensurvey_sondage';
49 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'=>
'Commentaires',
'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 'title' => array(
'type'=>
'mediumtext',
'label'=>
'Titre',
'enabled'=>
'1',
'position'=>35,
'notnull'=>1,
'visible'=>-1,),
113 'date_fin' => array(
'type'=>
'datetime',
'label'=>
'Datefin',
'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,),
129 public $commentaires;
132 public $fk_user_creat;
134 public $date_fin =
'';
143 public $allow_comments;
150 public $id_sondage_admin;
196 if (!$this->date_fin > 0) {
197 $this->error =
'BadValueForEndDate';
198 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
203 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"opensurvey_sondage(";
204 $sql .=
"id_sondage,";
205 $sql .=
"commentaires,";
206 $sql .=
"fk_user_creat,";
211 $sql .=
"mailsonde,";
212 $sql .=
"allow_comments,";
213 $sql .=
"allow_spy,";
216 $sql .=
") VALUES (";
217 $sql .=
"'".$this->db->escape($this->id_sondage).
"',";
219 $sql .=
" ".(int) $user->id.
",";
220 $sql .=
" '".$this->db->escape($this->title).
"',";
221 $sql .=
" '".$this->db->idate($this->date_fin).
"',";
222 $sql .=
" ".(int) $this->
status.
",";
223 $sql .=
" '".$this->db->escape($this->format).
"',";
224 $sql .=
" ".((int) $this->mailsonde).
",";
225 $sql .=
" ".((int) $this->allow_comments).
",";
226 $sql .=
" ".((int) $this->allow_spy).
",";
227 $sql .=
" '".$this->db->escape($this->sujet).
"',";
228 $sql .=
" ".((int) $conf->entity);
233 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
234 $resql = $this->db->query($sql);
237 $this->errors[] =
"Error ".$this->db->lasterror();
240 if (!$error && !$notrigger) {
242 $result = $this->
call_trigger(
'OPENSURVEY_CREATE', $user);
251 foreach ($this->errors as $errmsg) {
252 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
253 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
255 $this->db->rollback();
271 public function fetch($id, $numsurvey =
'')
274 $sql .=
" t.id_sondage,";
275 $sql .=
" t.titre as title,";
276 $sql .=
" t.commentaires as description,";
277 $sql .=
" t.mail_admin,";
278 $sql .=
" t.nom_admin,";
279 $sql .=
" t.fk_user_creat,";
280 $sql .=
" t.date_fin,";
281 $sql .=
" t.status,";
282 $sql .=
" t.format,";
283 $sql .=
" t.mailsonde,";
284 $sql .=
" t.allow_comments,";
285 $sql .=
" t.allow_spy,";
288 $sql .=
" FROM ".MAIN_DB_PREFIX.
"opensurvey_sondage as t";
289 $sql .=
" WHERE t.id_sondage = '".$this->db->escape($id ? $id : $numsurvey).
"'";
291 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
292 $resql = $this->db->query($sql);
294 if ($this->db->num_rows($resql)) {
295 $obj = $this->db->fetch_object($resql);
297 $this->id_sondage = $obj->id_sondage;
298 $this->
ref = $this->id_sondage;
301 $this->mail_admin = $obj->mail_admin;
302 $this->nom_admin = $obj->nom_admin;
303 $this->title = $obj->title;
304 $this->date_fin = $this->db->jdate($obj->date_fin);
305 $this->
status = $obj->status;
306 $this->format = $obj->format;
307 $this->mailsonde = $obj->mailsonde;
308 $this->allow_comments = $obj->allow_comments;
309 $this->allow_spy = $obj->allow_spy;
310 $this->sujet = $obj->sujet;
311 $this->fk_user_creat = $obj->fk_user_creat;
313 $this->date_m = $this->db->jdate(!empty($obj->tms) ? $obj->tms :
"");
316 $sondage = ($id ?
'id='.$id :
'sondageid='.$numsurvey);
317 $this->error =
'Fetch no poll found for '.$sondage;
322 $this->db->free($resql);
324 $this->error =
"Error ".$this->db->lasterror();
350 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"opensurvey_sondage SET";
351 $sql .=
" id_sondage=".(isset($this->id_sondage) ?
"'".$this->db->escape($this->id_sondage).
"'" :
"null").
",";
352 $sql .=
" commentaires=".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
353 $sql .=
" mail_admin=".(isset($this->mail_admin) ?
"'".$this->db->escape($this->mail_admin).
"'" :
"null").
",";
354 $sql .=
" nom_admin=".(isset($this->nom_admin) ?
"'".$this->db->escape($this->nom_admin).
"'" :
"null").
",";
355 $sql .=
" titre=".(isset($this->title) ?
"'".$this->db->escape($this->title).
"'" :
"null").
",";
356 $sql .=
" date_fin=".(dol_strlen($this->date_fin) != 0 ?
"'".$this->db->idate($this->date_fin).
"'" :
'null').
",";
357 $sql .=
" status=".(isset($this->
status) ?
"'".$this->db->escape($this->
status).
"'" :
"null").
",";
358 $sql .=
" format=".(isset($this->format) ?
"'".$this->db->escape($this->format).
"'" :
"null").
",";
359 $sql .=
" mailsonde=".(isset($this->mailsonde) ? ((int) $this->mailsonde) :
"null").
",";
360 $sql .=
" allow_comments=".((int) $this->allow_comments).
",";
361 $sql .=
" allow_spy=".((int) $this->allow_spy);
362 $sql .=
" WHERE id_sondage='".$this->db->escape($this->id_sondage).
"'";
366 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
367 $resql = $this->db->query($sql);
370 $this->errors[] =
"Error ".$this->db->lasterror();
373 if (!$error && !$notrigger) {
375 $result = $this->
call_trigger(
'OPENSURVEY_MODIFY', $user);
384 foreach ($this->errors as $errmsg) {
385 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
386 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
388 $this->db->rollback();
404 public function delete(
User $user, $notrigger = 0, $numsondage =
'')
406 global $conf, $langs;
409 if (empty($numsondage)) {
410 $numsondage = $this->id_sondage;
415 if (!$error && !$notrigger) {
417 $result = $this->
call_trigger(
'OPENSURVEY_DELETE', $user);
425 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"opensurvey_comments WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
426 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
427 $resql = $this->db->query($sql);
428 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"opensurvey_user_studs WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
429 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
430 $resql = $this->db->query($sql);
432 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"opensurvey_sondage";
433 $sql .=
" WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
435 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
436 $resql = $this->db->query($sql);
439 $this->errors[] =
"Error ".$this->db->lasterror();
445 foreach ($this->errors as $errmsg) {
446 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
447 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
449 $this->db->rollback();
466 global $conf, $langs;
468 $langs->load(
'opensurvey');
471 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"ShowSurvey").
'</u>';
472 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
473 $datas[
'title'] =
'<br><b>'.$langs->trans(
'Title').
':</b> '.$this->title;
487 public function getNomUrl($withpicto = 0, $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
489 global $conf, $langs;
491 if (!empty($conf->dol_no_mouse_hover)) {
498 'objecttype' => $this->element,
500 $classfortooltip =
'classfortooltip';
503 $classfortooltip =
'classforajaxtooltip';
504 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
510 $url = DOL_URL_ROOT.
'/opensurvey/card.php?id='.$this->id;
513 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
514 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
515 $add_save_lastsearch_values = 1;
517 if ($add_save_lastsearch_values) {
518 $url .=
'&save_lastsearch_values=1';
522 if (empty($notooltip)) {
524 $label = $langs->trans(
"ShowMyObject");
525 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
527 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
528 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
530 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
533 $linkstart =
'<a href="'.$url.
'"';
534 $linkstart .= $linkclose.
'>';
537 $result .= $linkstart;
539 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
541 if ($withpicto != 2) {
542 $result .= $this->ref;
558 $this->lines = array();
560 $sql =
"SELECT id_users, nom as name, reponses";
561 $sql .=
" FROM ".MAIN_DB_PREFIX.
"opensurvey_user_studs";
562 $sql .=
" WHERE id_sondage = '".$this->db->escape($this->id_sondage).
"'";
564 $resql = $this->db->query($sql);
567 $num = $this->db->num_rows($resql);
570 $obj = $this->db->fetch_object($resql);
571 $tmp = array(
'id_users'=>$obj->id_users,
'nom'=>$obj->name,
'reponses'=>$obj->reponses);
573 $this->lines[] = $tmp;
580 return count($this->lines);
593 $this->id_sondage =
'a12d5g';
594 $this->
description =
'Description of the specimen survey';
595 $this->mail_admin =
'email@email.com';
596 $this->nom_admin =
'surveyadmin';
597 $this->title =
'This is a specimen survey';
598 $this->date_fin =
dol_now() + 3600 * 24 * 10;
600 $this->format =
'classic';
601 $this->mailsonde = 0;
613 $sql =
'SELECT id_comment, usercomment, comment';
614 $sql .=
' FROM '.MAIN_DB_PREFIX.
'opensurvey_comments';
615 $sql .=
" WHERE id_sondage='".$this->db->escape($this->id_sondage).
"'";
616 $sql .=
" ORDER BY id_comment";
617 $resql = $this->db->query($sql);
620 $num_rows = $this->db->num_rows($resql);
623 while ($obj = $this->db->fetch_object($resql)) {
640 public function addComment($comment, $comment_user, $user_ip =
'')
643 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"opensurvey_comments (id_sondage, comment, usercomment, date_creation, ip)";
644 $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).
"'" :
'').
")";
645 $resql = $this->db->query($sql);
662 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'opensurvey_comments WHERE id_comment = '.((int) $id_comment).
' AND id_sondage = "'.$this->db->escape($this->id_sondage).
'"';
663 $resql = $this->db->query($sql);
679 $this->id_sondage = trim($this->id_sondage);
681 $this->mail_admin = trim($this->mail_admin);
682 $this->nom_admin = trim($this->nom_admin);
683 $this->title = trim($this->title);
685 $this->format = trim($this->format);
686 $this->mailsonde = ($this->mailsonde ? 1 : 0);
687 $this->allow_comments = ($this->allow_comments ? 1 : 0);
688 $this->allow_spy = ($this->allow_spy ? 1 : 0);
689 $this->sujet = trim($this->sujet);
715 global $langs, $conf;
717 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
728 $statusType =
'status'.$status;
729 if ($status == self::STATUS_VALIDATED) {
731 $statusType =
'status1';
733 $statusType =
'status4';
736 if ($status == self::STATUS_CLOSED) {
737 $statusType =
'status6';
740 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
753 $sql =
" SELECT COUNT(id_users) as nb FROM ".MAIN_DB_PREFIX.
"opensurvey_user_studs";
754 $sql .=
" WHERE id_sondage = '".$this->db->escape($this->
ref).
"'";
756 $resql = $this->db->query($sql);
758 $obj = $this->db->fetch_object($resql);
763 $this->error = $this->db->lasterror();
764 $this->errors[] = $this->error;
781 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
789 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
790 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
791 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
793 $sql .=
' WHERE 1 = 1';
797 if (count($filter) > 0) {
798 foreach ($filter as $key => $value) {
799 if ($key ==
't.rowid') {
800 $sqlwhere[] = $key.
" = ".((int) $value);
801 } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
802 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
803 } elseif ($key ==
'customsql') {
804 $sqlwhere[] = $value;
805 } elseif (strpos($value,
'%') ===
false) {
806 $sqlwhere[] = $key.
" IN (".$this->db->sanitize($this->db->escape($value)).
")";
808 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
812 if (count($sqlwhere) > 0) {
813 $sql .=
' AND ('.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere).
')';
816 if (!empty($sortfield)) {
817 $sql .= $this->db->order($sortfield, $sortorder);
819 if (!empty($limit)) {
820 $sql .= $this->db->plimit($limit, $offset);
823 $resql = $this->db->query($sql);
825 $num = $this->db->num_rows($resql);
827 while ($i < ($limit ? min($limit, $num) : $num)) {
828 $obj = $this->db->fetch_object($resql);
830 $record =
new self($this->db);
831 $record->setVarsFromFetchObj($obj);
833 $records[$record->id_sondage] = $record;
837 $this->db->free($resql);
841 $this->errors[] =
'Error '.$this->db->lasterror();
842 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
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.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
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
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 optionaly 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 $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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.