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,),
133 public $commentaires;
136 public $fk_user_creat;
138 public $date_fin =
'';
146 public $allow_comments;
161 public $id_sondage_admin;
206 if (!$this->date_fin > 0) {
207 $this->error =
'BadValueForEndDate';
208 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
213 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"opensurvey_sondage(";
214 $sql .=
"id_sondage,";
215 $sql .=
"commentaires,";
216 $sql .=
"fk_user_creat,";
221 $sql .=
"mailsonde,";
222 $sql .=
"allow_comments,";
223 $sql .=
"allow_spy,";
226 $sql .=
") VALUES (";
227 $sql .=
"'".$this->db->escape($this->id_sondage).
"',";
229 $sql .=
" ".(int) $user->id.
",";
230 $sql .=
" '".$this->db->escape($this->title).
"',";
231 $sql .=
" '".$this->db->idate($this->date_fin).
"',";
232 $sql .=
" ".(int) $this->
status.
",";
233 $sql .=
" '".$this->db->escape($this->format).
"',";
234 $sql .=
" ".((int) $this->mailsonde).
",";
235 $sql .=
" ".((int) $this->allow_comments).
",";
236 $sql .=
" ".((int) $this->allow_spy).
",";
237 $sql .=
" '".$this->db->escape($this->sujet).
"',";
238 $sql .=
" ".((int) $conf->entity);
243 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
244 $resql = $this->db->query($sql);
247 $this->errors[] =
"Error ".$this->db->lasterror();
250 if (!$error && !$notrigger) {
252 $result = $this->
call_trigger(
'OPENSURVEY_CREATE', $user);
261 foreach ($this->errors as $errmsg) {
262 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
263 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
265 $this->db->rollback();
281 public function fetch($id, $numsurvey =
'')
284 $sql .=
" t.id_sondage,";
285 $sql .=
" t.titre as title,";
286 $sql .=
" t.commentaires as description,";
287 $sql .=
" t.mail_admin,";
288 $sql .=
" t.nom_admin,";
289 $sql .=
" t.fk_user_creat,";
290 $sql .=
" t.date_fin,";
291 $sql .=
" t.status,";
292 $sql .=
" t.format,";
293 $sql .=
" t.mailsonde,";
294 $sql .=
" t.allow_comments,";
295 $sql .=
" t.allow_spy,";
298 $sql .=
" FROM ".MAIN_DB_PREFIX.
"opensurvey_sondage as t";
299 $sql .=
" WHERE t.id_sondage = '".$this->db->escape($id ? $id : $numsurvey).
"'";
301 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
302 $resql = $this->db->query($sql);
304 if ($this->db->num_rows($resql)) {
305 $obj = $this->db->fetch_object($resql);
307 $this->id_sondage = $obj->id_sondage;
308 $this->
ref = $this->id_sondage;
311 $this->mail_admin = $obj->mail_admin;
312 $this->nom_admin = $obj->nom_admin;
313 $this->title = $obj->title;
314 $this->date_fin = $this->db->jdate($obj->date_fin);
315 $this->
status = $obj->status;
316 $this->format = $obj->format;
317 $this->mailsonde = $obj->mailsonde;
318 $this->allow_comments = $obj->allow_comments;
319 $this->allow_spy = $obj->allow_spy;
320 $this->sujet = $obj->sujet;
321 $this->fk_user_creat = $obj->fk_user_creat;
323 $this->date_m = $this->db->jdate(!empty($obj->tms) ? $obj->tms :
"");
326 $sondage = ($id ?
'id='.$id :
'sondageid='.$numsurvey);
327 $this->error =
'Fetch no poll found for '.$sondage;
332 $this->db->free($resql);
334 $this->error =
"Error ".$this->db->lasterror();
360 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"opensurvey_sondage SET";
361 $sql .=
" id_sondage=".(isset($this->id_sondage) ?
"'".$this->db->escape($this->id_sondage).
"'" :
"null").
",";
362 $sql .=
" commentaires=".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
363 $sql .=
" mail_admin=".(isset($this->mail_admin) ?
"'".$this->db->escape($this->mail_admin).
"'" :
"null").
",";
364 $sql .=
" nom_admin=".(isset($this->nom_admin) ?
"'".$this->db->escape($this->nom_admin).
"'" :
"null").
",";
365 $sql .=
" titre=".(isset($this->title) ?
"'".$this->db->escape($this->title).
"'" :
"null").
",";
366 $sql .=
" date_fin=".(dol_strlen($this->date_fin) != 0 ?
"'".$this->db->idate($this->date_fin).
"'" :
'null').
",";
367 $sql .=
" status=".(isset($this->
status) ?
"'".$this->db->escape($this->
status).
"'" :
"null").
",";
368 $sql .=
" format=".(isset($this->format) ?
"'".$this->db->escape($this->format).
"'" :
"null").
",";
369 $sql .=
" mailsonde=".(isset($this->mailsonde) ? ((int) $this->mailsonde) :
"null").
",";
370 $sql .=
" allow_comments=".((int) $this->allow_comments).
",";
371 $sql .=
" allow_spy=".((int) $this->allow_spy);
372 $sql .=
" WHERE id_sondage='".$this->db->escape($this->id_sondage).
"'";
376 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
377 $resql = $this->db->query($sql);
380 $this->errors[] =
"Error ".$this->db->lasterror();
383 if (!$error && !$notrigger) {
385 $result = $this->
call_trigger(
'OPENSURVEY_MODIFY', $user);
394 foreach ($this->errors as $errmsg) {
395 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
396 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
398 $this->db->rollback();
414 public function delete(
User $user, $notrigger = 0, $numsondage =
'')
416 global $conf, $langs;
419 if (empty($numsondage)) {
420 $numsondage = $this->id_sondage;
425 if (!$error && !$notrigger) {
427 $result = $this->
call_trigger(
'OPENSURVEY_DELETE', $user);
435 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"opensurvey_comments WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
436 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
437 $resql = $this->db->query($sql);
438 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"opensurvey_user_studs WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
439 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
440 $resql = $this->db->query($sql);
442 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"opensurvey_sondage";
443 $sql .=
" WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
445 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
446 $resql = $this->db->query($sql);
449 $this->errors[] =
"Error ".$this->db->lasterror();
455 foreach ($this->errors as $errmsg) {
456 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
457 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
459 $this->db->rollback();
476 global $conf, $langs;
478 $langs->load(
'opensurvey');
481 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"ShowSurvey").
'</u>';
482 if (isset($this->
status)) {
483 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
485 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
486 if (!empty($this->date_fin)) {
487 $datas[
'expire_date'] =
'<br><b>'.$langs->trans(
'ExpireDate').
':</b> '.
dol_print_date($this->date_fin,
'day');
489 $datas[
'expire_date'] .=
img_warning($langs->trans(
"Expired"));
492 $datas[
'title'] =
'<br><b>'.$langs->trans(
'Title').
':</b> '.$this->title;
494 $datas[
'description'] =
'<br><b>'.$langs->trans(
'Description').
':</b> '.$this->description;
509 public function getNomUrl($withpicto = 0, $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
511 global $conf, $hookmanager, $langs;
513 if (!empty($conf->dol_no_mouse_hover)) {
520 'objecttype' => $this->element,
522 $classfortooltip =
'classfortooltip';
525 $classfortooltip =
'classforajaxtooltip';
526 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
532 $url = DOL_URL_ROOT.
'/opensurvey/card.php?id='.$this->id;
535 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
536 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
537 $add_save_lastsearch_values = 1;
539 if ($add_save_lastsearch_values) {
540 $url .=
'&save_lastsearch_values=1';
544 if (empty($notooltip)) {
546 $label = $langs->trans(
"ShowMyObject");
547 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
549 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
550 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
552 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
555 $linkstart =
'<a href="'.$url.
'"';
556 $linkstart .= $linkclose.
'>';
559 $result .= $linkstart;
561 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
563 if ($withpicto != 2) {
564 $result .= $this->ref;
569 $hookmanager->initHooks(array($this->element .
'dao'));
570 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
571 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
573 $result = $hookmanager->resPrint;
575 $result .= $hookmanager->resPrint;
590 $this->lines = array();
592 $sql =
"SELECT id_users, nom as name, reponses";
593 $sql .=
" FROM ".MAIN_DB_PREFIX.
"opensurvey_user_studs";
594 $sql .=
" WHERE id_sondage = '".$this->db->escape($this->id_sondage).
"'";
596 $resql = $this->db->query($sql);
599 $num = $this->db->num_rows($resql);
602 $obj = $this->db->fetch_object($resql);
603 $tmp = array(
'id_users' => $obj->id_users,
'nom' => $obj->name,
'reponses' => $obj->reponses);
605 $this->lines[] = $tmp;
612 return count($this->lines);
625 $this->id_sondage =
'a12d5g';
626 $this->
description =
'Description of the specimen survey';
627 $this->mail_admin =
'email@email.com';
628 $this->nom_admin =
'surveyadmin';
629 $this->title =
'This is a specimen survey';
630 $this->date_fin =
dol_now() + 3600 * 24 * 10;
632 $this->format =
'classic';
633 $this->mailsonde = 0;
647 $sql =
'SELECT id_comment, usercomment, comment';
648 $sql .=
' FROM '.MAIN_DB_PREFIX.
'opensurvey_comments';
649 $sql .=
" WHERE id_sondage='".$this->db->escape($this->id_sondage).
"'";
650 $sql .=
" ORDER BY id_comment";
651 $resql = $this->db->query($sql);
654 $num_rows = $this->db->num_rows($resql);
657 while ($obj = $this->db->fetch_object($resql)) {
674 public function addComment($comment, $comment_user, $user_ip =
'')
677 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"opensurvey_comments (id_sondage, comment, usercomment, date_creation, ip)";
678 $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).
"'" :
'').
")";
679 $resql = $this->db->query($sql);
696 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'opensurvey_comments WHERE id_comment = '.((int) $id_comment).
' AND id_sondage = "'.$this->db->escape($this->id_sondage).
'"';
697 $resql = $this->db->query($sql);
713 $this->id_sondage = trim($this->id_sondage);
715 $this->mail_admin = trim($this->mail_admin);
716 $this->nom_admin = trim($this->nom_admin);
717 $this->title = trim($this->title);
719 $this->format = trim($this->format);
720 $this->mailsonde = ($this->mailsonde ? 1 : 0);
721 $this->allow_comments = ($this->allow_comments ? 1 : 0);
722 $this->allow_spy = ($this->allow_spy ? 1 : 0);
723 $this->sujet = trim($this->sujet);
749 global $langs, $conf;
751 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
762 $statusType =
'status'.$status;
763 if ($status == self::STATUS_VALIDATED) {
765 $statusType =
'status1';
767 $statusType =
'status4';
770 if ($status == self::STATUS_CLOSED) {
771 $statusType =
'status6';
774 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
787 $sql =
" SELECT COUNT(id_users) as nb FROM ".MAIN_DB_PREFIX.
"opensurvey_user_studs";
788 $sql .=
" WHERE id_sondage = '".$this->db->escape($this->
ref).
"'";
790 $resql = $this->db->query($sql);
792 $obj = $this->db->fetch_object($resql);
797 $this->error = $this->db->lasterror();
798 $this->errors[] = $this->error;
816 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
824 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
825 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
826 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
828 $sql .=
' WHERE 1 = 1';
835 $this->errors[] = $errormessage;
836 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
840 if (!empty($sortfield)) {
841 $sql .= $this->db->order($sortfield, $sortorder);
843 if (!empty($limit)) {
844 $sql .= $this->db->plimit($limit, $offset);
847 $resql = $this->db->query($sql);
849 $num = $this->db->num_rows($resql);
851 while ($i < ($limit ? min($limit, $num) : $num)) {
852 $obj = $this->db->fetch_object($resql);
854 $record =
new self($this->db);
855 $record->setVarsFromFetchObj($obj);
857 $records[$record->id_sondage] = $record;
861 $this->db->free($resql);
865 $this->errors[] =
'Error '.$this->db->lasterror();
866 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
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 $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 dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.