28require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobject.class.php";
41 public $element =
'opensurvey_sondage';
46 public $table_element =
'opensurvey_sondage';
51 public $picto =
'poll';
77 public $fk_user_creat;
84 public $date_fin =
'';
111 public $allow_comments;
121 public $fields = array();
166 if (!$this->date_fin > 0) {
167 $this->error =
'BadValueForEndDate';
168 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
173 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"opensurvey_sondage(";
174 $sql .=
"id_sondage,";
175 $sql .=
"commentaires,";
176 $sql .=
"fk_user_creat,";
181 $sql .=
"mailsonde,";
182 $sql .=
"allow_comments,";
183 $sql .=
"allow_spy,";
186 $sql .=
") VALUES (";
187 $sql .=
"'".$this->db->escape($this->id_sondage).
"',";
189 $sql .=
" ".(int) $user->id.
",";
190 $sql .=
" '".$this->db->escape($this->title).
"',";
191 $sql .=
" '".$this->db->idate($this->date_fin).
"',";
192 $sql .=
" ".(int) $this->status.
",";
193 $sql .=
" '".$this->db->escape($this->format).
"',";
194 $sql .=
" ".((int) $this->mailsonde).
",";
195 $sql .=
" ".((int) $this->allow_comments).
",";
196 $sql .=
" ".((int) $this->allow_spy).
",";
197 $sql .=
" '".$this->db->escape($this->sujet).
"',";
198 $sql .=
" ".((int) $conf->entity);
203 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
204 $resql = $this->db->query($sql);
206 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
209 if (!$error && !$notrigger) {
210 global $langs, $conf;
213 $result = $this->
call_trigger(
'OPENSURVEY_CREATE', $user);
222 foreach ($this->errors as $errmsg) {
223 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
224 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
226 $this->db->rollback();
242 public function fetch($id, $numsurvey =
'')
245 $sql .=
" t.id_sondage,";
246 $sql .=
" t.titre as title,";
247 $sql .=
" t.commentaires as description,";
248 $sql .=
" t.mail_admin,";
249 $sql .=
" t.nom_admin,";
250 $sql .=
" t.fk_user_creat,";
251 $sql .=
" t.date_fin,";
252 $sql .=
" t.status,";
253 $sql .=
" t.format,";
254 $sql .=
" t.mailsonde,";
255 $sql .=
" t.allow_comments,";
256 $sql .=
" t.allow_spy,";
259 $sql .=
" FROM ".MAIN_DB_PREFIX.
"opensurvey_sondage as t";
260 $sql .=
" WHERE t.id_sondage = '".$this->db->escape($id ? $id : $numsurvey).
"'";
262 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
263 $resql = $this->db->query($sql);
265 if ($this->db->num_rows($resql)) {
266 $obj = $this->db->fetch_object($resql);
268 $this->id_sondage = $obj->id_sondage;
269 $this->
ref = $this->id_sondage;
272 $this->mail_admin = $obj->mail_admin;
273 $this->nom_admin = $obj->nom_admin;
274 $this->title = $obj->title;
275 $this->date_fin = $this->db->jdate($obj->date_fin);
276 $this->status = $obj->status;
277 $this->format = $obj->format;
278 $this->mailsonde = $obj->mailsonde;
279 $this->allow_comments = $obj->allow_comments;
280 $this->allow_spy = $obj->allow_spy;
281 $this->sujet = $obj->sujet;
282 $this->fk_user_creat = $obj->fk_user_creat;
284 $this->date_m = $this->db->jdate(!empty($obj->tls) ? $obj->tls :
"");
287 $sondage = ($id ?
'id='.$id :
'sondageid='.$numsurvey);
288 $this->error =
'Fetch no poll found for '.$sondage;
293 $this->db->free($resql);
295 $this->error =
"Error ".$this->db->lasterror();
312 global $conf, $langs;
322 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"opensurvey_sondage SET";
323 $sql .=
" id_sondage=".(isset($this->id_sondage) ?
"'".$this->db->escape($this->id_sondage).
"'" :
"null").
",";
324 $sql .=
" commentaires=".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
325 $sql .=
" mail_admin=".(isset($this->mail_admin) ?
"'".$this->db->escape($this->mail_admin).
"'" :
"null").
",";
326 $sql .=
" nom_admin=".(isset($this->nom_admin) ?
"'".$this->db->escape($this->nom_admin).
"'" :
"null").
",";
327 $sql .=
" titre=".(isset($this->title) ?
"'".$this->db->escape($this->title).
"'" :
"null").
",";
328 $sql .=
" date_fin=".(dol_strlen($this->date_fin) != 0 ?
"'".$this->db->idate($this->date_fin).
"'" :
'null').
",";
329 $sql .=
" status=".(isset($this->status) ?
"'".$this->db->escape($this->status).
"'" :
"null").
",";
330 $sql .=
" format=".(isset($this->format) ?
"'".$this->db->escape($this->format).
"'" :
"null").
",";
331 $sql .=
" mailsonde=".(isset($this->mailsonde) ? ((int) $this->mailsonde) :
"null").
",";
332 $sql .=
" allow_comments=".((int) $this->allow_comments).
",";
333 $sql .=
" allow_spy=".((int) $this->allow_spy);
334 $sql .=
" WHERE id_sondage='".$this->db->escape($this->id_sondage).
"'";
338 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
339 $resql = $this->db->query($sql);
342 $this->errors[] =
"Error ".$this->db->lasterror();
345 if (!$error && !$notrigger) {
347 $result = $this->
call_trigger(
'OPENSURVEY_MODIFY', $user);
356 foreach ($this->errors as $errmsg) {
357 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
358 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
360 $this->db->rollback();
376 public function delete(
User $user, $notrigger = 0, $numsondage =
'')
378 global $conf, $langs;
381 if (empty($numsondage)) {
382 $numsondage = $this->id_sondage;
387 if (!$error && !$notrigger) {
389 $result = $this->
call_trigger(
'OPENSURVEY_DELETE', $user);
397 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"opensurvey_comments WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
398 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
399 $resql = $this->db->query($sql);
400 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"opensurvey_user_studs WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
401 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
402 $resql = $this->db->query($sql);
404 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"opensurvey_sondage";
405 $sql .=
" WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
407 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
408 $resql = $this->db->query($sql);
410 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
416 foreach ($this->errors as $errmsg) {
417 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
418 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
420 $this->db->rollback();
437 global $conf, $langs;
439 $langs->load(
'opensurvey');
442 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"ShowSurvey").
'</u>';
443 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
444 $datas[
'title'] =
'<br><b>'.$langs->trans(
'Title').
':</b> '.$this->title;
458 public function getNomUrl($withpicto = 0, $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
460 global $conf, $langs;
462 if (!empty($conf->dol_no_mouse_hover)) {
469 'objecttype' => $this->element,
471 $classfortooltip =
'classfortooltip';
474 $classfortooltip =
'classforajaxtooltip';
475 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
481 $url = DOL_URL_ROOT.
'/opensurvey/card.php?id='.$this->id;
484 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
485 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
486 $add_save_lastsearch_values = 1;
488 if ($add_save_lastsearch_values) {
489 $url .=
'&save_lastsearch_values=1';
493 if (empty($notooltip)) {
494 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
495 $label = $langs->trans(
"ShowMyObject");
496 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
498 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
499 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
501 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
504 $linkstart =
'<a href="'.$url.
'"';
505 $linkstart .= $linkclose.
'>';
508 $result .= $linkstart;
510 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
512 if ($withpicto != 2) {
513 $result .= $this->ref;
529 $this->lines = array();
531 $sql =
"SELECT id_users, nom as name, reponses";
532 $sql .=
" FROM ".MAIN_DB_PREFIX.
"opensurvey_user_studs";
533 $sql .=
" WHERE id_sondage = '".$this->db->escape($this->id_sondage).
"'";
535 $resql = $this->db->query($sql);
538 $num = $this->db->num_rows($resql);
541 $obj = $this->db->fetch_object($resql);
542 $tmp = array(
'id_users'=>$obj->id_users,
'nom'=>$obj->name,
'reponses'=>$obj->reponses);
544 $this->lines[] = $tmp;
551 return count($this->lines);
564 $this->id_sondage =
'a12d5g';
565 $this->
description =
'Description of the specimen survey';
566 $this->mail_admin =
'email@email.com';
567 $this->nom_admin =
'surveyadmin';
568 $this->title =
'This is a specimen survey';
569 $this->date_fin =
dol_now() + 3600 * 24 * 10;
571 $this->format =
'classic';
572 $this->mailsonde = 0;
584 $sql =
'SELECT id_comment, usercomment, comment';
585 $sql .=
' FROM '.MAIN_DB_PREFIX.
'opensurvey_comments';
586 $sql .=
" WHERE id_sondage='".$this->db->escape($this->id_sondage).
"'";
587 $sql .=
" ORDER BY id_comment";
588 $resql = $this->db->query($sql);
591 $num_rows = $this->db->num_rows($resql);
594 while ($obj = $this->db->fetch_object($resql)) {
611 public function addComment($comment, $comment_user, $user_ip =
'')
614 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"opensurvey_comments (id_sondage, comment, usercomment, date_creation, ip)";
615 $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).
"'" :
'').
")";
616 $resql = $this->db->query($sql);
633 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'opensurvey_comments WHERE id_comment = '.((int) $id_comment).
' AND id_sondage = "'.$this->db->escape($this->id_sondage).
'"';
634 $resql = $this->db->query($sql);
650 $this->id_sondage = trim($this->id_sondage);
652 $this->mail_admin = trim($this->mail_admin);
653 $this->nom_admin = trim($this->nom_admin);
654 $this->title = trim($this->title);
655 $this->status = (int) $this->status;
656 $this->format = trim($this->format);
657 $this->mailsonde = ($this->mailsonde ? 1 : 0);
658 $this->allow_comments = ($this->allow_comments ? 1 : 0);
659 $this->allow_spy = ($this->allow_spy ? 1 : 0);
660 $this->sujet = trim($this->sujet);
672 return $this->
LibStatut($this->status, $mode);
686 global $langs, $conf;
688 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
699 $statusType =
'status'.$status;
700 if ($status == self::STATUS_VALIDATED) {
702 $statusType =
'status1';
704 $statusType =
'status4';
707 if ($status == self::STATUS_CLOSED) {
708 $statusType =
'status6';
711 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
724 $sql =
" SELECT COUNT(id_users) as nb FROM ".MAIN_DB_PREFIX.
"opensurvey_user_studs";
725 $sql .=
" WHERE id_sondage = '".$this->db->escape($this->
ref).
"'";
727 $resql = $this->db->query($sql);
729 $obj = $this->db->fetch_object($resql);
734 $this->error = $this->db->lasterror();
735 $this->errors[] = $this->error;
Parent class of all other business classes (invoices, contracts, proposals, orders,...
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
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 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)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.