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 =
'';
178 public $allow_comments;
193 public $id_sondage_admin;
238 if (!$this->date_fin > 0) {
239 $this->error =
'BadValueForEndDate';
240 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
245 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"opensurvey_sondage(";
246 $sql .=
"id_sondage,";
247 $sql .=
"commentaires,";
248 $sql .=
"fk_user_creat,";
253 $sql .=
"mailsonde,";
254 $sql .=
"allow_comments,";
255 $sql .=
"allow_spy,";
258 $sql .=
") VALUES (";
259 $sql .=
"'".$this->db->escape($this->id_sondage).
"',";
261 $sql .=
" ".(int) $user->id.
",";
262 $sql .=
" '".$this->db->escape($this->title).
"',";
263 $sql .=
" '".$this->db->idate($this->date_fin).
"',";
264 $sql .=
" ".(int) $this->
status.
",";
265 $sql .=
" '".$this->db->escape($this->format).
"',";
266 $sql .=
" ".((int) $this->mailsonde).
",";
267 $sql .=
" ".((int) $this->allow_comments).
",";
268 $sql .=
" ".((int) $this->allow_spy).
",";
269 $sql .=
" '".$this->db->escape($this->sujet).
"',";
270 $sql .=
" ".((int)
$conf->entity);
275 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
276 $resql = $this->db->query($sql);
279 $this->errors[] =
"Error ".$this->db->lasterror();
282 if (!$error && !$notrigger) {
284 $result = $this->
call_trigger(
'OPENSURVEY_CREATE', $user);
293 foreach ($this->errors as $errmsg) {
294 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
295 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
297 $this->db->rollback();
313 public function fetch($id, $numsurvey =
'')
316 $sql .=
" t.id_sondage,";
317 $sql .=
" t.titre as title,";
318 $sql .=
" t.commentaires as description,";
319 $sql .=
" t.mail_admin,";
320 $sql .=
" t.nom_admin,";
321 $sql .=
" t.fk_user_creat,";
322 $sql .=
" t.date_fin,";
323 $sql .=
" t.status,";
324 $sql .=
" t.format,";
325 $sql .=
" t.mailsonde,";
326 $sql .=
" t.allow_comments,";
327 $sql .=
" t.allow_spy,";
330 $sql .=
" FROM ".MAIN_DB_PREFIX.
"opensurvey_sondage as t";
331 $sql .=
" WHERE t.id_sondage = '".$this->db->escape($id ? $id : $numsurvey).
"'";
333 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
334 $resql = $this->db->query($sql);
336 if ($this->db->num_rows($resql)) {
337 $obj = $this->db->fetch_object($resql);
339 $this->id_sondage = $obj->id_sondage;
340 $this->
ref = $this->id_sondage;
343 $this->mail_admin = $obj->mail_admin;
344 $this->nom_admin = $obj->nom_admin;
345 $this->title = $obj->title;
346 $this->date_fin = $this->db->jdate($obj->date_fin);
347 $this->
status = $obj->status;
348 $this->format = $obj->format;
349 $this->mailsonde = $obj->mailsonde;
350 $this->allow_comments = $obj->allow_comments;
351 $this->allow_spy = $obj->allow_spy;
352 $this->sujet = $obj->sujet;
353 $this->fk_user_creat = $obj->fk_user_creat;
355 $this->date_m = $this->db->jdate(!empty($obj->tms) ? $obj->tms :
"");
358 $sondage = ($id ?
'id='.$id :
'sondageid='.$numsurvey);
359 $this->error =
'Fetch no poll found for '.$sondage;
364 $this->db->free($resql);
366 $this->error =
"Error ".$this->db->lasterror();
392 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"opensurvey_sondage SET";
393 $sql .=
" id_sondage=".(isset($this->id_sondage) ?
"'".$this->db->escape($this->id_sondage).
"'" :
"null").
",";
394 $sql .=
" commentaires=".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
395 $sql .=
" mail_admin=".(isset($this->mail_admin) ?
"'".$this->db->escape($this->mail_admin).
"'" :
"null").
",";
396 $sql .=
" nom_admin=".(isset($this->nom_admin) ?
"'".$this->db->escape($this->nom_admin).
"'" :
"null").
",";
397 $sql .=
" titre=".(isset($this->title) ?
"'".$this->db->escape($this->title).
"'" :
"null").
",";
398 $sql .=
" date_fin=".(dol_strlen($this->date_fin) != 0 ?
"'".$this->db->idate($this->date_fin).
"'" :
'null').
",";
399 $sql .=
" status=".(!empty($this->
status) ? (int) $this->
status :
"null").
",";
400 $sql .=
" format=".(isset($this->format) ?
"'".$this->db->escape($this->format).
"'" :
"null").
",";
401 $sql .=
" mailsonde=".(isset($this->mailsonde) ? ((int) $this->mailsonde) :
"null").
",";
402 $sql .=
" allow_comments=".((int) $this->allow_comments).
",";
403 $sql .=
" allow_spy=".((int) $this->allow_spy);
404 $sql .=
" WHERE id_sondage='".$this->db->escape($this->id_sondage).
"'";
408 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
409 $resql = $this->db->query($sql);
412 $this->errors[] =
"Error ".$this->db->lasterror();
415 if (!$error && !$notrigger) {
417 $result = $this->
call_trigger(
'OPENSURVEY_MODIFY', $user);
426 foreach ($this->errors as $errmsg) {
427 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
428 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
430 $this->db->rollback();
446 public function delete(
User $user, $notrigger = 0, $numsondage =
'')
448 global
$conf, $langs;
451 if (empty($numsondage)) {
452 $numsondage = $this->id_sondage;
457 if (!$error && !$notrigger) {
459 $result = $this->
call_trigger(
'OPENSURVEY_DELETE', $user);
467 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"opensurvey_comments WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
468 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
469 $resql = $this->db->query($sql);
470 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"opensurvey_user_studs WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
471 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
472 $resql = $this->db->query($sql);
474 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"opensurvey_sondage";
475 $sql .=
" WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
477 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
478 $resql = $this->db->query($sql);
481 $this->errors[] =
"Error ".$this->db->lasterror();
487 foreach ($this->errors as $errmsg) {
488 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
489 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
491 $this->db->rollback();
507 global
$conf, $langs;
509 $langs->load(
'opensurvey');
512 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"ShowSurvey").
'</u>';
513 if (isset($this->
status)) {
514 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
516 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
517 if (!empty($this->date_fin)) {
518 $datas[
'expire_date'] =
'<br><b>'.$langs->trans(
'ExpireDate').
':</b> '.
dol_print_date($this->date_fin,
'day');
520 $datas[
'expire_date'] .=
img_warning($langs->trans(
"Expired"));
523 $datas[
'title'] =
'<br><b>'.$langs->trans(
'Title').
':</b> '.$this->title;
525 $datas[
'description'] =
'<br><b>'.$langs->trans(
'Description').
':</b> '.$this->description;
540 public function getNomUrl($withpicto = 0, $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
542 global
$conf, $hookmanager, $langs;
544 if (!empty(
$conf->dol_no_mouse_hover)) {
551 'objecttype' => $this->element,
553 $classfortooltip =
'classfortooltip';
556 $classfortooltip =
'classforajaxtooltip';
557 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
563 $url = DOL_URL_ROOT.
'/opensurvey/card.php?id='.$this->id;
566 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
567 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
568 $add_save_lastsearch_values = 1;
570 if ($add_save_lastsearch_values) {
571 $url .=
'&save_lastsearch_values=1';
575 if (empty($notooltip)) {
577 $label = $langs->trans(
"ShowMyObject");
578 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
580 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
581 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
583 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
586 $linkstart =
'<a href="'.$url.
'"';
587 $linkstart .= $linkclose.
'>';
590 $result .= $linkstart;
592 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
594 if ($withpicto != 2) {
595 $result .= $this->ref;
600 $hookmanager->initHooks(array($this->element .
'dao'));
601 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
602 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
604 $result = $hookmanager->resPrint;
606 $result .= $hookmanager->resPrint;
621 $this->lines = array();
623 $sql =
"SELECT id_users, nom as name, reponses";
624 $sql .=
" FROM ".MAIN_DB_PREFIX.
"opensurvey_user_studs";
625 $sql .=
" WHERE id_sondage = '".$this->db->escape($this->id_sondage).
"'";
627 $resql = $this->db->query($sql);
630 $num = $this->db->num_rows($resql);
633 $obj = $this->db->fetch_object($resql);
634 $tmp = array(
'id_users' => $obj->id_users,
'nom' => $obj->name,
'reponses' => $obj->reponses);
636 $this->lines[] = $tmp;
643 return count($this->lines);
656 $this->id_sondage =
'a12d5g';
657 $this->
description =
'Description of the specimen survey';
658 $this->mail_admin =
'email@email.com';
659 $this->nom_admin =
'surveyadmin';
660 $this->title =
'This is a specimen survey';
661 $this->date_fin =
dol_now() + 3600 * 24 * 10;
663 $this->format =
'classic';
664 $this->mailsonde = 0;
678 $sql =
'SELECT id_comment, usercomment, comment';
679 $sql .=
' FROM '.MAIN_DB_PREFIX.
'opensurvey_comments';
680 $sql .=
" WHERE id_sondage='".$this->db->escape($this->id_sondage).
"'";
681 $sql .=
" ORDER BY id_comment";
682 $resql = $this->db->query($sql);
685 $num_rows = $this->db->num_rows($resql);
688 while ($obj = $this->db->fetch_object($resql)) {
705 public function addComment($comment, $comment_user, $user_ip =
'')
708 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"opensurvey_comments (id_sondage, comment, usercomment, date_creation, ip)";
709 $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).
"'" :
'').
")";
710 $resql = $this->db->query($sql);
727 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'opensurvey_comments WHERE id_comment = '.((int) $id_comment).
' AND id_sondage = "'.$this->db->escape($this->id_sondage).
'"';
728 $resql = $this->db->query($sql);
744 $this->id_sondage = trim($this->id_sondage);
746 $this->mail_admin = trim($this->mail_admin);
747 $this->nom_admin = trim($this->nom_admin);
748 $this->title = trim($this->title);
750 $this->format = trim($this->format);
751 $this->mailsonde = ($this->mailsonde ? 1 : 0);
752 $this->allow_comments = ($this->allow_comments ? 1 : 0);
753 $this->allow_spy = ($this->allow_spy ? 1 : 0);
754 $this->sujet = trim($this->sujet);
780 global $langs,
$conf;
782 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
793 $statusType =
'status'.$status;
794 if ($status == self::STATUS_VALIDATED) {
796 $statusType =
'status1';
798 $statusType =
'status4';
801 if ($status == self::STATUS_CLOSED) {
802 $statusType =
'status6';
805 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
818 $sql =
" SELECT COUNT(id_users) as nb FROM ".MAIN_DB_PREFIX.
"opensurvey_user_studs";
819 $sql .=
" WHERE id_sondage = '".$this->db->escape($this->
ref).
"'";
821 $resql = $this->db->query($sql);
823 $obj = $this->db->fetch_object($resql);
828 $this->error = $this->db->lasterror();
829 $this->errors[] = $this->error;
847 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
855 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
856 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
857 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
859 $sql .=
' WHERE 1 = 1';
866 $this->errors[] = $errormessage;
867 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
871 if (!empty($sortfield)) {
872 $sql .= $this->db->order($sortfield, $sortorder);
874 if (!empty($limit)) {
875 $sql .= $this->db->plimit($limit, $offset);
878 $resql = $this->db->query($sql);
880 $num = $this->db->num_rows($resql);
882 while ($i < ($limit ? min($limit, $num) : $num)) {
883 $obj = $this->db->fetch_object($resql);
885 $record =
new self($this->db);
886 $record->setVarsFromFetchObj($obj);
888 $records[$record->id_sondage] = $record;
892 $this->db->free($resql);
896 $this->errors[] =
'Error '.$this->db->lasterror();
897 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).
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...