28 require_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 =
'';
109 public $allow_comments;
159 if (!$this->date_fin > 0) {
160 $this->error =
'BadValueForEndDate';
161 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
166 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"opensurvey_sondage(";
167 $sql .=
"id_sondage,";
168 $sql .=
"commentaires,";
169 $sql .=
"fk_user_creat,";
174 $sql .=
"mailsonde,";
175 $sql .=
"allow_comments,";
176 $sql .=
"allow_spy,";
179 $sql .=
") VALUES (";
180 $sql .=
"'".$this->db->escape($this->id_sondage).
"',";
182 $sql .=
" ".(int) $user->id.
",";
183 $sql .=
" '".$this->db->escape($this->title).
"',";
184 $sql .=
" '".$this->db->idate($this->date_fin).
"',";
185 $sql .=
" ".(int) $this->status.
",";
186 $sql .=
" '".$this->db->escape($this->format).
"',";
187 $sql .=
" ".((int) $this->mailsonde).
",";
188 $sql .=
" ".((int) $this->allow_comments).
",";
189 $sql .=
" ".((int) $this->allow_spy).
",";
190 $sql .=
" '".$this->db->escape($this->sujet).
"',";
191 $sql .=
" ".((int) $conf->entity);
196 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
199 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
202 if (!$error && !$notrigger) {
203 global $langs, $conf;
206 $result = $this->
call_trigger(
'OPENSURVEY_CREATE', $user);
215 foreach ($this->errors as $errmsg) {
216 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
217 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
219 $this->
db->rollback();
235 public function fetch($id, $numsurvey =
'')
238 $sql .=
" t.id_sondage,";
239 $sql .=
" t.titre as title,";
240 $sql .=
" t.commentaires as description,";
241 $sql .=
" t.mail_admin,";
242 $sql .=
" t.nom_admin,";
243 $sql .=
" t.fk_user_creat,";
244 $sql .=
" t.date_fin,";
245 $sql .=
" t.status,";
246 $sql .=
" t.format,";
247 $sql .=
" t.mailsonde,";
248 $sql .=
" t.allow_comments,";
249 $sql .=
" t.allow_spy,";
252 $sql .=
" FROM ".MAIN_DB_PREFIX.
"opensurvey_sondage as t";
253 $sql .=
" WHERE t.id_sondage = '".$this->db->escape($id ? $id : $numsurvey).
"'";
255 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
259 $obj = $this->
db->fetch_object(
$resql);
261 $this->id_sondage = $obj->id_sondage;
262 $this->
ref = $this->id_sondage;
265 $this->mail_admin = $obj->mail_admin;
266 $this->nom_admin = $obj->nom_admin;
267 $this->title = $obj->title;
268 $this->date_fin = $this->
db->jdate($obj->date_fin);
269 $this->status = $obj->status;
270 $this->format = $obj->format;
271 $this->mailsonde = $obj->mailsonde;
272 $this->allow_comments = $obj->allow_comments;
273 $this->allow_spy = $obj->allow_spy;
274 $this->sujet = $obj->sujet;
275 $this->fk_user_creat = $obj->fk_user_creat;
277 $this->date_m = $this->
db->jdate($obj->tls);
280 $sondage = ($id ?
'id='.$id :
'sondageid='.$numsurvey);
281 $this->error =
'Fetch no poll found for '.$sondage;
288 $this->error =
"Error ".$this->db->lasterror();
305 global $conf, $langs;
315 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"opensurvey_sondage SET";
316 $sql .=
" id_sondage=".(isset($this->id_sondage) ?
"'".$this->db->escape($this->id_sondage).
"'" :
"null").
",";
317 $sql .=
" commentaires=".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
318 $sql .=
" mail_admin=".(isset($this->mail_admin) ?
"'".$this->db->escape($this->mail_admin).
"'" :
"null").
",";
319 $sql .=
" nom_admin=".(isset($this->nom_admin) ?
"'".$this->db->escape($this->nom_admin).
"'" :
"null").
",";
320 $sql .=
" titre=".(isset($this->title) ?
"'".$this->db->escape($this->title).
"'" :
"null").
",";
321 $sql .=
" date_fin=".(dol_strlen($this->date_fin) != 0 ?
"'".$this->db->idate($this->date_fin).
"'" :
'null').
",";
322 $sql .=
" status=".(isset($this->status) ?
"'".$this->db->escape($this->status).
"'" :
"null").
",";
323 $sql .=
" format=".(isset($this->format) ?
"'".$this->db->escape($this->format).
"'" :
"null").
",";
324 $sql .=
" mailsonde=".(isset($this->mailsonde) ? ((int) $this->mailsonde) :
"null").
",";
325 $sql .=
" allow_comments=".((int) $this->allow_comments).
",";
326 $sql .=
" allow_spy=".((int) $this->allow_spy);
327 $sql .=
" WHERE id_sondage='".$this->db->escape($this->id_sondage).
"'";
331 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
335 $this->errors[] =
"Error ".$this->db->lasterror();
338 if (!$error && !$notrigger) {
340 $result = $this->
call_trigger(
'OPENSURVEY_MODIFY', $user);
349 foreach ($this->errors as $errmsg) {
350 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
351 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
353 $this->
db->rollback();
369 public function delete(
User $user, $notrigger = 0, $numsondage =
'')
371 global $conf, $langs;
374 if (empty($numsondage)) {
375 $numsondage = $this->id_sondage;
380 if (!$error && !$notrigger) {
382 $result = $this->
call_trigger(
'OPENSURVEY_DELETE', $user);
390 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"opensurvey_comments WHERE id_sondage = '".$this->
db->escape($numsondage).
"'";
391 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
393 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"opensurvey_user_studs WHERE id_sondage = '".$this->
db->escape($numsondage).
"'";
394 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
397 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"opensurvey_sondage";
398 $sql .=
" WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
400 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
403 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
409 foreach ($this->errors as $errmsg) {
410 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
411 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
413 $this->
db->rollback();
430 public function getNomUrl($withpicto = 0, $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
432 global $db, $conf, $langs;
433 global $dolibarr_main_authentication, $dolibarr_main_demo;
436 if (!empty($conf->dol_no_mouse_hover)) {
442 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"ShowSurvey").
'</u>';
444 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->
ref.
'<br>';
445 $label .=
'<b>'.$langs->trans(
'Title').
':</b> '.$this->title.
'<br>';
447 $url = DOL_URL_ROOT.
'/opensurvey/card.php?id='.$this->id;
450 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
451 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
452 $add_save_lastsearch_values = 1;
454 if ($add_save_lastsearch_values) {
455 $url .=
'&save_lastsearch_values=1';
459 if (empty($notooltip)) {
460 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
461 $label = $langs->trans(
"ShowMyObject");
462 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
464 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
465 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
467 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
470 $linkstart =
'<a href="'.$url.
'"';
471 $linkstart .= $linkclose.
'>';
474 $result .= $linkstart;
476 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
478 if ($withpicto != 2) {
479 $result .= $this->ref;
495 $this->lines = array();
497 $sql =
"SELECT id_users, nom as name, reponses";
498 $sql .=
" FROM ".MAIN_DB_PREFIX.
"opensurvey_user_studs";
499 $sql .=
" WHERE id_sondage = '".$this->db->escape($this->id_sondage).
"'";
507 $obj = $this->
db->fetch_object(
$resql);
508 $tmp = array(
'id_users'=>$obj->id_users,
'nom'=>$obj->name,
'reponses'=>$obj->reponses);
510 $this->lines[] = $tmp;
517 return count($this->lines);
530 $this->id_sondage =
'a12d5g';
531 $this->
description =
'Description of the specimen survey';
532 $this->mail_admin =
'email@email.com';
533 $this->nom_admin =
'surveyadmin';
534 $this->title =
'This is a specimen survey';
535 $this->date_fin =
dol_now() + 3600 * 24 * 10;
537 $this->format =
'classic';
538 $this->mailsonde = 0;
550 $sql =
'SELECT id_comment, usercomment, comment';
551 $sql .=
' FROM '.MAIN_DB_PREFIX.
'opensurvey_comments';
552 $sql .=
" WHERE id_sondage='".$this->db->escape($this->id_sondage).
"'";
553 $sql .=
" ORDER BY id_comment";
557 $num_rows = $this->
db->num_rows(
$resql);
560 while ($obj = $this->
db->fetch_object(
$resql)) {
578 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"opensurvey_comments (id_sondage, comment, usercomment)";
579 $sql .=
" VALUES ('".$this->db->escape($this->id_sondage).
"','".$this->
db->escape($comment).
"','".$this->
db->escape($comment_user).
"')";
597 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'opensurvey_comments WHERE id_comment = '.((int) $id_comment).
' AND id_sondage = "'.$this->
db->escape($this->id_sondage).
'"';
614 $this->id_sondage = trim($this->id_sondage);
616 $this->mail_admin = trim($this->mail_admin);
617 $this->nom_admin = trim($this->nom_admin);
618 $this->title = trim($this->title);
619 $this->status = (int) $this->status;
620 $this->format = trim($this->format);
621 $this->mailsonde = ($this->mailsonde ? 1 : 0);
622 $this->allow_comments = ($this->allow_comments ? 1 : 0);
623 $this->allow_spy = ($this->allow_spy ? 1 : 0);
624 $this->sujet = trim($this->sujet);
636 return $this->
LibStatut($this->status, $mode);
650 global $langs, $conf;
652 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
663 $statusType =
'status'.$status;
664 if ($status == self::STATUS_VALIDATED) {
666 $statusType =
'status1';
668 $statusType =
'status4';
671 if ($status == self::STATUS_CLOSED) {
672 $statusType =
'status6';
675 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
688 $sql .=
" SELECT COUNT(id_users) as nb FROM ".MAIN_DB_PREFIX.
"opensurvey_user_studs";
689 $sql .=
" WHERE id_sondage = '".$this->db->escape($this->
ref).
"'";
693 $obj = $this->
db->fetch_object(
$resql);
698 $this->error = $this->
db->lasterror();
699 $this->errors[] = $this->error;