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 =
'';
111 public $allow_comments;
161 if (!$this->date_fin > 0) {
162 $this->error =
'BadValueForEndDate';
163 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
168 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"opensurvey_sondage(";
169 $sql .=
"id_sondage,";
170 $sql .=
"commentaires,";
171 $sql .=
"fk_user_creat,";
176 $sql .=
"mailsonde,";
177 $sql .=
"allow_comments,";
178 $sql .=
"allow_spy,";
181 $sql .=
") VALUES (";
182 $sql .=
"'".$this->db->escape($this->id_sondage).
"',";
184 $sql .=
" ".(int) $user->id.
",";
185 $sql .=
" '".$this->db->escape($this->title).
"',";
186 $sql .=
" '".$this->db->idate($this->date_fin).
"',";
187 $sql .=
" ".(int) $this->status.
",";
188 $sql .=
" '".$this->db->escape($this->format).
"',";
189 $sql .=
" ".((int) $this->mailsonde).
",";
190 $sql .=
" ".((int) $this->allow_comments).
",";
191 $sql .=
" ".((int) $this->allow_spy).
",";
192 $sql .=
" '".$this->db->escape($this->sujet).
"',";
193 $sql .=
" ".((int) $conf->entity);
198 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
201 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
204 if (!$error && !$notrigger) {
205 global $langs, $conf;
208 $result = $this->
call_trigger(
'OPENSURVEY_CREATE', $user);
217 foreach ($this->errors as $errmsg) {
218 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
219 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
221 $this->
db->rollback();
237 public function fetch($id, $numsurvey =
'')
240 $sql .=
" t.id_sondage,";
241 $sql .=
" t.titre as title,";
242 $sql .=
" t.commentaires as description,";
243 $sql .=
" t.mail_admin,";
244 $sql .=
" t.nom_admin,";
245 $sql .=
" t.fk_user_creat,";
246 $sql .=
" t.date_fin,";
247 $sql .=
" t.status,";
248 $sql .=
" t.format,";
249 $sql .=
" t.mailsonde,";
250 $sql .=
" t.allow_comments,";
251 $sql .=
" t.allow_spy,";
254 $sql .=
" FROM ".MAIN_DB_PREFIX.
"opensurvey_sondage as t";
255 $sql .=
" WHERE t.id_sondage = '".$this->db->escape($id ? $id : $numsurvey).
"'";
257 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
261 $obj = $this->
db->fetch_object(
$resql);
263 $this->id_sondage = $obj->id_sondage;
264 $this->
ref = $this->id_sondage;
267 $this->mail_admin = $obj->mail_admin;
268 $this->nom_admin = $obj->nom_admin;
269 $this->title = $obj->title;
270 $this->date_fin = $this->
db->jdate($obj->date_fin);
271 $this->status = $obj->status;
272 $this->format = $obj->format;
273 $this->mailsonde = $obj->mailsonde;
274 $this->allow_comments = $obj->allow_comments;
275 $this->allow_spy = $obj->allow_spy;
276 $this->sujet = $obj->sujet;
277 $this->fk_user_creat = $obj->fk_user_creat;
279 $this->date_m = $this->
db->jdate(!empty($obj->tls) ? $obj->tls :
"");
282 $sondage = ($id ?
'id='.$id :
'sondageid='.$numsurvey);
283 $this->error =
'Fetch no poll found for '.$sondage;
290 $this->error =
"Error ".$this->db->lasterror();
307 global $conf, $langs;
317 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"opensurvey_sondage SET";
318 $sql .=
" id_sondage=".(isset($this->id_sondage) ?
"'".$this->db->escape($this->id_sondage).
"'" :
"null").
",";
319 $sql .=
" commentaires=".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
320 $sql .=
" mail_admin=".(isset($this->mail_admin) ?
"'".$this->db->escape($this->mail_admin).
"'" :
"null").
",";
321 $sql .=
" nom_admin=".(isset($this->nom_admin) ?
"'".$this->db->escape($this->nom_admin).
"'" :
"null").
",";
322 $sql .=
" titre=".(isset($this->title) ?
"'".$this->db->escape($this->title).
"'" :
"null").
",";
323 $sql .=
" date_fin=".(dol_strlen($this->date_fin) != 0 ?
"'".$this->db->idate($this->date_fin).
"'" :
'null').
",";
324 $sql .=
" status=".(isset($this->status) ?
"'".$this->db->escape($this->status).
"'" :
"null").
",";
325 $sql .=
" format=".(isset($this->format) ?
"'".$this->db->escape($this->format).
"'" :
"null").
",";
326 $sql .=
" mailsonde=".(isset($this->mailsonde) ? ((int) $this->mailsonde) :
"null").
",";
327 $sql .=
" allow_comments=".((int) $this->allow_comments).
",";
328 $sql .=
" allow_spy=".((int) $this->allow_spy);
329 $sql .=
" WHERE id_sondage='".$this->db->escape($this->id_sondage).
"'";
333 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
337 $this->errors[] =
"Error ".$this->db->lasterror();
340 if (!$error && !$notrigger) {
342 $result = $this->
call_trigger(
'OPENSURVEY_MODIFY', $user);
351 foreach ($this->errors as $errmsg) {
352 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
353 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
355 $this->
db->rollback();
371 public function delete(
User $user, $notrigger = 0, $numsondage =
'')
373 global $conf, $langs;
376 if (empty($numsondage)) {
377 $numsondage = $this->id_sondage;
382 if (!$error && !$notrigger) {
384 $result = $this->
call_trigger(
'OPENSURVEY_DELETE', $user);
392 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"opensurvey_comments WHERE id_sondage = '".$this->
db->escape($numsondage).
"'";
393 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
395 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"opensurvey_user_studs WHERE id_sondage = '".$this->
db->escape($numsondage).
"'";
396 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
399 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"opensurvey_sondage";
400 $sql .=
" WHERE id_sondage = '".$this->db->escape($numsondage).
"'";
402 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
405 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
411 foreach ($this->errors as $errmsg) {
412 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
413 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
415 $this->
db->rollback();
432 public function getNomUrl($withpicto = 0, $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
434 global $db, $conf, $langs;
435 global $dolibarr_main_authentication, $dolibarr_main_demo;
438 if (!empty($conf->dol_no_mouse_hover)) {
444 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"ShowSurvey").
'</u>';
446 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->
ref.
'<br>';
447 $label .=
'<b>'.$langs->trans(
'Title').
':</b> '.$this->title.
'<br>';
449 $url = DOL_URL_ROOT.
'/opensurvey/card.php?id='.$this->id;
452 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
453 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
454 $add_save_lastsearch_values = 1;
456 if ($add_save_lastsearch_values) {
457 $url .=
'&save_lastsearch_values=1';
461 if (empty($notooltip)) {
462 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
463 $label = $langs->trans(
"ShowMyObject");
464 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
466 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
467 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
469 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
472 $linkstart =
'<a href="'.$url.
'"';
473 $linkstart .= $linkclose.
'>';
476 $result .= $linkstart;
478 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
480 if ($withpicto != 2) {
481 $result .= $this->ref;
497 $this->lines = array();
499 $sql =
"SELECT id_users, nom as name, reponses";
500 $sql .=
" FROM ".MAIN_DB_PREFIX.
"opensurvey_user_studs";
501 $sql .=
" WHERE id_sondage = '".$this->db->escape($this->id_sondage).
"'";
509 $obj = $this->
db->fetch_object(
$resql);
510 $tmp = array(
'id_users'=>$obj->id_users,
'nom'=>$obj->name,
'reponses'=>$obj->reponses);
512 $this->lines[] = $tmp;
519 return count($this->lines);
532 $this->id_sondage =
'a12d5g';
533 $this->
description =
'Description of the specimen survey';
534 $this->mail_admin =
'email@email.com';
535 $this->nom_admin =
'surveyadmin';
536 $this->title =
'This is a specimen survey';
537 $this->date_fin =
dol_now() + 3600 * 24 * 10;
539 $this->format =
'classic';
540 $this->mailsonde = 0;
552 $sql =
'SELECT id_comment, usercomment, comment';
553 $sql .=
' FROM '.MAIN_DB_PREFIX.
'opensurvey_comments';
554 $sql .=
" WHERE id_sondage='".$this->db->escape($this->id_sondage).
"'";
555 $sql .=
" ORDER BY id_comment";
559 $num_rows = $this->
db->num_rows(
$resql);
562 while ($obj = $this->
db->fetch_object(
$resql)) {
579 public function addComment($comment, $comment_user, $user_ip =
'')
582 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"opensurvey_comments (id_sondage, comment, usercomment, date_creation, ip)";
583 $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).
"'" :
'').
")";
601 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'opensurvey_comments WHERE id_comment = '.((int) $id_comment).
' AND id_sondage = "'.$this->
db->escape($this->id_sondage).
'"';
618 $this->id_sondage = trim($this->id_sondage);
620 $this->mail_admin = trim($this->mail_admin);
621 $this->nom_admin = trim($this->nom_admin);
622 $this->title = trim($this->title);
623 $this->status = (int) $this->status;
624 $this->format = trim($this->format);
625 $this->mailsonde = ($this->mailsonde ? 1 : 0);
626 $this->allow_comments = ($this->allow_comments ? 1 : 0);
627 $this->allow_spy = ($this->allow_spy ? 1 : 0);
628 $this->sujet = trim($this->sujet);
640 return $this->
LibStatut($this->status, $mode);
654 global $langs, $conf;
656 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
667 $statusType =
'status'.$status;
668 if ($status == self::STATUS_VALIDATED) {
670 $statusType =
'status1';
672 $statusType =
'status4';
675 if ($status == self::STATUS_CLOSED) {
676 $statusType =
'status6';
679 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
692 $sql =
" SELECT COUNT(id_users) as nb FROM ".MAIN_DB_PREFIX.
"opensurvey_user_studs";
693 $sql .=
" WHERE id_sondage = '".$this->db->escape($this->
ref).
"'";
697 $obj = $this->
db->fetch_object(
$resql);
702 $this->error = $this->
db->lasterror();
703 $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.
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.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
print *****$script_file(".$version.") pid 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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.