PageRenderTime 70ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 3ms

/application/helpers/common_helper.php

https://bitbucket.org/machaven/limesurvey
PHP | 7809 lines | 5988 code | 657 blank | 1164 comment | 801 complexity | b1dd78b5b367b1d4d436ad4ec9c009dc MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause, GPL-3.0, LGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /*
  3. * LimeSurvey
  4. * Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz
  5. * All rights reserved.
  6. * License: GNU/GPL License v2 or later, see LICENSE.php
  7. * LimeSurvey is free software. This version may have been modified pursuant
  8. * to the GNU General Public License, and as distributed it includes or
  9. * is derivative of works licensed under the GNU General Public License or
  10. * other free or open source software licenses.
  11. * See COPYRIGHT.php for copyright notices and details.
  12. */
  13. Yii::import('application.helpers.sanitize_helper', true);
  14. /**
  15. * Simple function to sort the permissions by title
  16. *
  17. * @param mixed $aPermissionA Permission A to compare
  18. * @param mixed $aPermissionB Permission B to compare
  19. */
  20. function comparePermission($aPermissionA,$aPermissionB)
  21. {
  22. if($aPermissionA['title'] >$aPermissionB['title']) {
  23. return 1;
  24. }
  25. else {
  26. return -1;
  27. }
  28. }
  29. /**
  30. * getQuestionTypeList() Returns list of question types available in LimeSurvey. Edit this if you are adding a new
  31. * question type
  32. *
  33. * @param string $SelectedCode Value of the Question Type (defaults to "T")
  34. * @param string $ReturnType Type of output from this function (defaults to selector)
  35. *
  36. * @return depending on $ReturnType param, returns a straight "array" of question types, or an <option></option> list
  37. *
  38. * Explanation of questiontype array:
  39. *
  40. * description : Question description
  41. * subquestions : 0= Does not support subquestions x=Number of subquestion scales
  42. * answerscales : 0= Does not need answers x=Number of answer scales (usually 1, but e.g. for dual scale question set to 2)
  43. * assessable : 0=Does not support assessment values when editing answerd 1=Support assessment values
  44. */
  45. function getQuestionTypeList($SelectedCode = "T", $ReturnType = "selector")
  46. {
  47. $publicurl = Yii::app()->getConfig('publicurl');
  48. $clang = Yii::app()->lang;
  49. $group['Arrays'] = $clang->gT('Arrays');
  50. $group['MaskQuestions'] = $clang->gT("Mask questions");
  51. $group['SinChoiceQues'] = $clang->gT("Single choice questions");
  52. $group['MulChoiceQues'] = $clang->gT("Multiple choice questions");
  53. $group['TextQuestions'] = $clang->gT("Text questions");
  54. $qtypes = array(
  55. "1" => array('description' => $clang->gT("Array dual scale"),
  56. 'group' => $group['Arrays'],
  57. 'subquestions' => 1,
  58. 'assessable' => 1,
  59. 'hasdefaultvalues' => 0,
  60. 'answerscales' => 2),
  61. "5" => array('description' => $clang->gT("5 Point Choice"),
  62. 'group' => $group['SinChoiceQues'],
  63. 'subquestions' => 0,
  64. 'hasdefaultvalues' => 0,
  65. 'assessable' => 0,
  66. 'answerscales' => 0),
  67. "A" => array('description' => $clang->gT("Array (5 Point Choice)"),
  68. 'group' => $group['Arrays'],
  69. 'subquestions' => 1,
  70. 'hasdefaultvalues' => 0,
  71. 'assessable' => 1,
  72. 'answerscales' => 0),
  73. "B" => array('description' => $clang->gT("Array (10 Point Choice)"),
  74. 'group' => $group['Arrays'],
  75. 'subquestions' => 1,
  76. 'hasdefaultvalues' => 0,
  77. 'assessable' => 1,
  78. 'answerscales' => 0),
  79. "C" => array('description' => $clang->gT("Array (Yes/No/Uncertain)"),
  80. 'group' => $group['Arrays'],
  81. 'subquestions' => 1,
  82. 'hasdefaultvalues' => 0,
  83. 'assessable' => 1,
  84. 'answerscales' => 0),
  85. "D" => array('description' => $clang->gT("Date/Time"),
  86. 'group' => $group['MaskQuestions'],
  87. 'subquestions' => 0,
  88. 'hasdefaultvalues' => 1,
  89. 'assessable' => 0,
  90. 'answerscales' => 0),
  91. "E" => array('description' => $clang->gT("Array (Increase/Same/Decrease)"),
  92. 'group' => $group['Arrays'],
  93. 'subquestions' => 1,
  94. 'hasdefaultvalues' => 0,
  95. 'assessable' => 1,
  96. 'answerscales' => 0),
  97. "F" => array('description' => $clang->gT("Array"),
  98. 'group' => $group['Arrays'],
  99. 'subquestions' => 1,
  100. 'hasdefaultvalues' => 0,
  101. 'assessable' => 1,
  102. 'answerscales' => 1),
  103. "G" => array('description' => $clang->gT("Gender"),
  104. 'group' => $group['MaskQuestions'],
  105. 'subquestions' => 0,
  106. 'hasdefaultvalues' => 0,
  107. 'assessable' => 0,
  108. 'answerscales' => 0),
  109. "H" => array('description' => $clang->gT("Array by column"),
  110. 'group' => $group['Arrays'],
  111. 'hasdefaultvalues' => 0,
  112. 'subquestions' => 1,
  113. 'assessable' => 1,
  114. 'answerscales' => 1),
  115. "I" => array('description' => $clang->gT("Language Switch"),
  116. 'group' => $group['MaskQuestions'],
  117. 'hasdefaultvalues' => 0,
  118. 'subquestions' => 0,
  119. 'assessable' => 0,
  120. 'answerscales' => 0),
  121. "K" => array('description' => $clang->gT("Multiple Numerical Input"),
  122. 'group' => $group['MaskQuestions'],
  123. 'hasdefaultvalues' => 1,
  124. 'subquestions' => 1,
  125. 'assessable' => 1,
  126. 'answerscales' => 0),
  127. "L" => array('description' => $clang->gT("List (Radio)"),
  128. 'group' => $group['SinChoiceQues'],
  129. 'subquestions' => 0,
  130. 'hasdefaultvalues' => 1,
  131. 'assessable' => 1,
  132. 'answerscales' => 1),
  133. "M" => array('description' => $clang->gT("Multiple choice"),
  134. 'group' => $group['MulChoiceQues'],
  135. 'subquestions' => 1,
  136. 'hasdefaultvalues' => 1,
  137. 'assessable' => 1,
  138. 'answerscales' => 0),
  139. "N" => array('description' => $clang->gT("Numerical Input"),
  140. 'group' => $group['MaskQuestions'],
  141. 'subquestions' => 0,
  142. 'hasdefaultvalues' => 1,
  143. 'assessable' => 0,
  144. 'answerscales' => 0),
  145. "O" => array('description' => $clang->gT("List with comment"),
  146. 'group' => $group['SinChoiceQues'],
  147. 'subquestions' => 0,
  148. 'hasdefaultvalues' => 1,
  149. 'assessable' => 1,
  150. 'answerscales' => 1),
  151. "P" => array('description' => $clang->gT("Multiple choice with comments"),
  152. 'group' => $group['MulChoiceQues'],
  153. 'subquestions' => 1,
  154. 'hasdefaultvalues' => 1,
  155. 'assessable' => 1,
  156. 'answerscales' => 0),
  157. "Q" => array('description' => $clang->gT("Multiple Short Text"),
  158. 'group' => $group['TextQuestions'],
  159. 'subquestions' => 1,
  160. 'hasdefaultvalues' => 1,
  161. 'assessable' => 0,
  162. 'answerscales' => 0),
  163. "R" => array('description' => $clang->gT("Ranking"),
  164. 'group' => $group['MaskQuestions'],
  165. 'subquestions' => 0,
  166. 'hasdefaultvalues' => 0,
  167. 'assessable' => 1,
  168. 'answerscales' => 1),
  169. "S" => array('description' => $clang->gT("Short Free Text"),
  170. 'group' => $group['TextQuestions'],
  171. 'subquestions' => 0,
  172. 'hasdefaultvalues' => 1,
  173. 'assessable' => 0,
  174. 'answerscales' => 0),
  175. "T" => array('description' => $clang->gT("Long Free Text"),
  176. 'group' => $group['TextQuestions'],
  177. 'subquestions' => 0,
  178. 'hasdefaultvalues' => 1,
  179. 'assessable' => 0,
  180. 'answerscales' => 0),
  181. "U" => array('description' => $clang->gT("Huge Free Text"),
  182. 'group' => $group['TextQuestions'],
  183. 'subquestions' => 0,
  184. 'hasdefaultvalues' => 1,
  185. 'assessable' => 0,
  186. 'answerscales' => 0),
  187. "X" => array('description' => $clang->gT("Text display"),
  188. 'group' => $group['MaskQuestions'],
  189. 'subquestions' => 0,
  190. 'hasdefaultvalues' => 0,
  191. 'assessable' => 0,
  192. 'answerscales' => 0),
  193. "Y" => array('description' => $clang->gT("Yes/No"),
  194. 'group' => $group['MaskQuestions'],
  195. 'subquestions' => 0,
  196. 'hasdefaultvalues' => 0,
  197. 'assessable' => 0,
  198. 'answerscales' => 0),
  199. "!" => array('description' => $clang->gT("List (Dropdown)"),
  200. 'group' => $group['SinChoiceQues'],
  201. 'subquestions' => 0,
  202. 'hasdefaultvalues' => 1,
  203. 'assessable' => 1,
  204. 'answerscales' => 1),
  205. ":" => array('description' => $clang->gT("Array (Numbers)"),
  206. 'group' => $group['Arrays'],
  207. 'subquestions' => 2,
  208. 'hasdefaultvalues' => 0,
  209. 'assessable' => 1,
  210. 'answerscales' => 0),
  211. ";" => array('description' => $clang->gT("Array (Texts)"),
  212. 'group' => $group['Arrays'],
  213. 'subquestions' => 2,
  214. 'hasdefaultvalues' => 0,
  215. 'assessable' => 0,
  216. 'answerscales' => 0),
  217. "|" => array('description' => $clang->gT("File upload"),
  218. 'group' => $group['MaskQuestions'],
  219. 'subquestions' => 0,
  220. 'hasdefaultvalues' => 0,
  221. 'assessable' => 0,
  222. 'answerscales' => 0),
  223. "*" => array('description' => $clang->gT("Equation"),
  224. 'group' => $group['MaskQuestions'],
  225. 'subquestions' => 0,
  226. 'hasdefaultvalues' => 0,
  227. 'assessable' => 0,
  228. 'answerscales' => 0),
  229. );
  230. asort($qtypes);
  231. if ($ReturnType == "array")
  232. return $qtypes;
  233. if ($ReturnType == "group")
  234. {
  235. foreach ($qtypes as $qkey => $qtype)
  236. {
  237. $newqType[$qtype['group']][$qkey] = $qtype;
  238. }
  239. $qtypeselecter = "";
  240. foreach ($newqType as $group => $members)
  241. {
  242. $qtypeselecter .= '<optgroup label="' . $group . '">';
  243. foreach ($members as $TypeCode => $TypeProperties)
  244. {
  245. $qtypeselecter .= "<option value='$TypeCode'";
  246. if ($SelectedCode == $TypeCode)
  247. {
  248. $qtypeselecter .= " selected='selected'";
  249. }
  250. $qtypeselecter .= ">{$TypeProperties['description']}</option>\n";
  251. }
  252. $qtypeselecter .= '</optgroup>';
  253. }
  254. return $qtypeselecter;
  255. };
  256. $qtypeselecter = "";
  257. foreach ($qtypes as $TypeCode => $TypeProperties)
  258. {
  259. $qtypeselecter .= "<option value='$TypeCode'";
  260. if ($SelectedCode == $TypeCode)
  261. {
  262. $qtypeselecter .= " selected='selected'";
  263. }
  264. $qtypeselecter .= ">{$TypeProperties['description']}</option>\n";
  265. }
  266. return $qtypeselecter;
  267. }
  268. /**
  269. * isStandardTemplate returns true if a template is a standard template
  270. * This function does not check if a template actually exists
  271. *
  272. * @param mixed $sTemplateName template name to look for
  273. * @return bool True if standard template, otherwise false
  274. */
  275. function isStandardTemplate($sTemplateName)
  276. {
  277. return in_array($sTemplateName,array('basic',
  278. 'bluengrey',
  279. 'business_grey',
  280. 'citronade',
  281. 'clear_logo',
  282. 'default',
  283. 'eirenicon',
  284. 'limespired',
  285. 'mint_idea',
  286. 'sherpa',
  287. 'vallendar'));
  288. }
  289. /**
  290. * getSurveyList() Queries the database (survey table) for a list of existing surveys
  291. *
  292. * @param boolean $returnarray if set to true an array instead of an HTML option list is given back
  293. * @return string This string is returned containing <option></option> formatted list of existing surveys
  294. *
  295. */
  296. function getSurveyList($returnarray=false, $surveyid=false)
  297. {
  298. static $cached = null;
  299. $timeadjust = getGlobalSetting('timeadjust');
  300. $clang = new Limesurvey_lang(Yii::app()->session['adminlang']);
  301. if(is_null($cached)) {
  302. if (!hasGlobalPermission('USER_RIGHT_SUPERADMIN'))
  303. $surveyidresult = Survey::model()->permission(Yii::app()->user->getId())->with(array('languagesettings'=>array('condition'=>'surveyls_language=language')))->findAll();
  304. else
  305. $surveyidresult = Survey::model()->with(array('languagesettings'=>array('condition'=>'surveyls_language=language')))->findAll();
  306. $surveynames = array();
  307. foreach ($surveyidresult as $result)
  308. {
  309. $surveynames[] = array_merge($result->attributes, $result->languagesettings[0]->attributes);
  310. }
  311. $cached = $surveynames;
  312. } else {
  313. $surveynames = $cached;
  314. }
  315. $surveyselecter = "";
  316. if ($returnarray===true) return $surveynames;
  317. $activesurveys='';
  318. $inactivesurveys='';
  319. $expiredsurveys='';
  320. if ($surveynames)
  321. {
  322. foreach($surveynames as $sv)
  323. {
  324. $surveylstitle=flattenText($sv['surveyls_title']);
  325. if (strlen($surveylstitle)>45)
  326. {
  327. $surveylstitle = htmlspecialchars(mb_strcut(html_entity_decode($surveylstitle,ENT_QUOTES,'UTF-8'), 0, 45, 'UTF-8'))."...";
  328. }
  329. if($sv['active']!='Y')
  330. {
  331. $inactivesurveys .= "<option ";
  332. if(Yii::app()->user->getId() == $sv['owner_id'])
  333. {
  334. $inactivesurveys .= " style=\"font-weight: bold;\"";
  335. }
  336. if ($sv['sid'] == $surveyid)
  337. {
  338. $inactivesurveys .= " selected='selected'"; $svexist = 1;
  339. }
  340. $inactivesurveys .=" value='{$sv['sid']}'>{$surveylstitle}</option>\n";
  341. } elseif($sv['expires']!='' && $sv['expires'] < dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", $timeadjust))
  342. {
  343. $expiredsurveys .="<option ";
  344. if (Yii::app()->user->getId() == $sv['owner_id'])
  345. {
  346. $expiredsurveys .= " style=\"font-weight: bold;\"";
  347. }
  348. if ($sv['sid'] == $surveyid)
  349. {
  350. $expiredsurveys .= " selected='selected'"; $svexist = 1;
  351. }
  352. $expiredsurveys .=" value='{$sv['sid']}'>{$surveylstitle}</option>\n";
  353. } else
  354. {
  355. $activesurveys .= "<option ";
  356. if(Yii::app()->user->getId() == $sv['owner_id'])
  357. {
  358. $activesurveys .= " style=\"font-weight: bold;\"";
  359. }
  360. if ($sv['sid'] == $surveyid)
  361. {
  362. $activesurveys .= " selected='selected'"; $svexist = 1;
  363. }
  364. $activesurveys .=" value='{$sv['sid']}'>{$surveylstitle}</option>\n";
  365. }
  366. } // End Foreach
  367. }
  368. //Only show each activesurvey group if there are some
  369. if ($activesurveys!='')
  370. {
  371. $surveyselecter .= "<optgroup label='".$clang->gT("Active")."' class='activesurveyselect'>\n";
  372. $surveyselecter .= $activesurveys . "</optgroup>";
  373. }
  374. if ($expiredsurveys!='')
  375. {
  376. $surveyselecter .= "<optgroup label='".$clang->gT("Expired")."' class='expiredsurveyselect'>\n";
  377. $surveyselecter .= $expiredsurveys . "</optgroup>";
  378. }
  379. if ($inactivesurveys!='')
  380. {
  381. $surveyselecter .= "<optgroup label='".$clang->gT("Inactive")."' class='inactivesurveyselect'>\n";
  382. $surveyselecter .= $inactivesurveys . "</optgroup>";
  383. }
  384. if (!isset($svexist))
  385. {
  386. $surveyselecter = "<option selected='selected' value=''>".$clang->gT("Please choose...")."</option>\n".$surveyselecter;
  387. } else
  388. {
  389. $surveyselecter = "<option value=''>".$clang->gT("None")."</option>\n".$surveyselecter;
  390. }
  391. return $surveyselecter;
  392. }
  393. /**
  394. * Returns true if a user has permissions in the particular survey
  395. *
  396. * @param $iSID The survey ID
  397. * @param $sPermission
  398. * @param $sCRUD
  399. * @param $iUID User ID - if not given the one of the current user is used
  400. * @return bool
  401. */
  402. function hasSurveyPermission($iSID, $sPermission, $sCRUD, $iUID=null)
  403. {
  404. if (!in_array($sCRUD,array('create','read','update','delete','import','export'))) return false;
  405. $sCRUD=$sCRUD.'_p';
  406. $thissurvey=getSurveyInfo($iSID);
  407. if (!$thissurvey) return false;
  408. $aSurveyPermissionCache = Yii::app()->getConfig("aSurveyPermissionCache");
  409. if (is_null($iUID))
  410. {
  411. if (!Yii::app()->user->getIsGuest()) $iUID = Yii::app()->session['loginID'];
  412. else return false;
  413. // Some user have acces to whole survey settings
  414. if (Yii::app()->session['USER_RIGHT_SUPERADMIN']==1) return true;
  415. if ($thissurvey && $iUID==$thissurvey['owner_id']) return true;
  416. }
  417. if (!isset($aSurveyPermissionCache[$iSID][$iUID][$sPermission][$sCRUD]))
  418. {
  419. $query = Survey_permissions::model()->findByAttributes(array("sid"=> $iSID,"uid"=> $iUID,"permission"=>$sPermission));
  420. $bPermission = is_null($query) ? array() : $query->attributes;
  421. if (!isset($bPermission[$sCRUD]) || $bPermission[$sCRUD]==0)
  422. {
  423. $bPermission=false;
  424. }
  425. else
  426. {
  427. $bPermission=true;
  428. }
  429. $aSurveyPermissionCache[$iSID][$iUID][$sPermission][$sCRUD]=$bPermission;
  430. }
  431. Yii::app()->setConfig("aSurveyPermissionCache", $aSurveyPermissionCache);
  432. return $aSurveyPermissionCache[$iSID][$iUID][$sPermission][$sCRUD];
  433. }
  434. /**
  435. * Returns true if a user has global permission for a certain action. Available permissions are
  436. *
  437. * USER_RIGHT_CREATE_SURVEY
  438. * USER_RIGHT_CONFIGURATOR
  439. * USER_RIGHT_CREATE_USER
  440. * USER_RIGHT_DELETE_USER
  441. * USER_RIGHT_SUPERADMIN
  442. * USER_RIGHT_MANAGE_TEMPLATE
  443. * USER_RIGHT_MANAGE_LABEL
  444. *
  445. * @param $sPermission
  446. * @return bool
  447. */
  448. function hasGlobalPermission($sPermission)
  449. {
  450. if (!Yii::app()->user->getIsGuest()) $iUID = !Yii::app()->user->getId();
  451. else return false;
  452. if (Yii::app()->session['USER_RIGHT_SUPERADMIN']==1) return true; //Superadmin has access to all
  453. if (Yii::app()->session[$sPermission]==1)
  454. {
  455. return true;
  456. }
  457. else
  458. {
  459. return false;
  460. }
  461. }
  462. function getTemplateList()
  463. {
  464. $usertemplaterootdir=Yii::app()->getConfig("usertemplaterootdir");
  465. $standardtemplaterootdir=Yii::app()->getConfig("standardtemplaterootdir");
  466. if (!$usertemplaterootdir) {die("getTemplateList() no template directory");}
  467. if ($handle = opendir($standardtemplaterootdir))
  468. {
  469. while (false !== ($file = readdir($handle)))
  470. {
  471. if (!is_file("$standardtemplaterootdir/$file") && $file != "." && $file != ".." && $file!=".svn" && isStandardTemplate($file))
  472. {
  473. $list_of_files[$file] = $standardtemplaterootdir.DIRECTORY_SEPARATOR.$file;
  474. }
  475. }
  476. closedir($handle);
  477. }
  478. if ($handle = opendir($usertemplaterootdir))
  479. {
  480. while (false !== ($file = readdir($handle)))
  481. {
  482. if (!is_file("$usertemplaterootdir/$file") && $file != "." && $file != ".." && $file!=".svn")
  483. {
  484. $list_of_files[$file] = $usertemplaterootdir.DIRECTORY_SEPARATOR.$file;
  485. }
  486. }
  487. closedir($handle);
  488. }
  489. ksort($list_of_files);
  490. return $list_of_files;
  491. }
  492. function getAdminThemeList()
  493. {
  494. // $usertemplaterootdir=Yii::app()->getConfig("usertemplaterootdir");
  495. $standardtemplaterootdir=Yii::app()->getConfig("styledir");
  496. // if (!$usertemplaterootdir) {die("getTemplateList() no template directory");}
  497. if ($handle = opendir($standardtemplaterootdir))
  498. {
  499. while (false !== ($file = readdir($handle)))
  500. {
  501. if (!is_file("$standardtemplaterootdir/$file") && $file != "." && $file != ".." && $file!=".svn")
  502. {
  503. $list_of_files[$file] = $standardtemplaterootdir.DIRECTORY_SEPARATOR.$file;
  504. }
  505. }
  506. closedir($handle);
  507. }
  508. /* if ($handle = opendir($usertemplaterootdir))
  509. {
  510. while (false !== ($file = readdir($handle)))
  511. {
  512. if (!is_file("$usertemplaterootdir/$file") && $file != "." && $file != ".." && $file!=".svn")
  513. {
  514. $list_of_files[$file] = $usertemplaterootdir.DIRECTORY_SEPARATOR.$file;
  515. }
  516. }
  517. closedir($handle);
  518. } */
  519. ksort($list_of_files);
  520. return $list_of_files;
  521. }
  522. /**
  523. * getQuestions() queries the database for an list of all questions matching the current survey and group id
  524. *
  525. * @return This string is returned containing <option></option> formatted list of questions in the current survey and group
  526. */
  527. function getQuestions($surveyid,$gid,$selectedqid)
  528. {
  529. $clang = Yii::app()->lang;
  530. $s_lang = Survey::model()->findByPk($surveyid)->language;
  531. $qrows = Questions::model()->findAllByAttributes(array('sid' => $surveyid, 'gid' => $gid, 'language' => $s_lang, 'parent_qid' => 0),array('order'=>'question_order'));
  532. if (!isset($sQuestionselecter)) {$sQuestionselecter="";}
  533. foreach ($qrows as $qrow)
  534. {
  535. $qrow = $qrow->attributes;
  536. $qrow['title'] = strip_tags($qrow['title']);
  537. $link = Yii::app()->getController()->createUrl("/admin/survey/sa/view/surveyid/".$surveyid."/gid/".$gid."/qid/".$qrow['qid']);
  538. $sQuestionselecter .= "<option value='{$link}'";
  539. if ($selectedqid == $qrow['qid'])
  540. {
  541. $sQuestionselecter .= " selected='selected'";
  542. $qexists=true;
  543. }
  544. $sQuestionselecter .=">{$qrow['title']}:";
  545. $sQuestionselecter .= " ";
  546. $question=flattenText($qrow['question']);
  547. if (strlen($question)<35)
  548. {
  549. $sQuestionselecter .= $question;
  550. }
  551. else
  552. {
  553. $sQuestionselecter .= htmlspecialchars(mb_strcut(html_entity_decode($question,ENT_QUOTES,'UTF-8'), 0, 35, 'UTF-8'))."...";
  554. }
  555. $sQuestionselecter .= "</option>\n";
  556. }
  557. if (!isset($qexists))
  558. {
  559. $sQuestionselecter = "<option selected='selected'>".$clang->gT("Please choose...")."</option>\n".$sQuestionselecter;
  560. }
  561. else
  562. {
  563. $link = Yii::app()->getController()->createUrl("/admin/survey/sa/view/surveyid/".$surveyid."/gid/".$gid);
  564. $sQuestionselecter = "<option value='{$link}'>".$clang->gT("None")."</option>\n".$sQuestionselecter;
  565. }
  566. return $sQuestionselecter;
  567. }
  568. /**
  569. * getGidPrevious() returns the Gid of the group prior to the current active group
  570. *
  571. * @param string $surveyid
  572. * @param string $gid
  573. *
  574. * @return The Gid of the previous group
  575. */
  576. function getGidPrevious($surveyid, $gid)
  577. {
  578. $clang = Yii::app()->lang;
  579. if (!$surveyid) {$surveyid=returnGlobal('sid');}
  580. $s_lang = Survey::model()->findByPk($surveyid)->language;
  581. $qresult = Groups::model()->findAllByAttributes(array('sid' => $surveyid, 'language' => $s_lang), array('order'=>'group_order'));
  582. $i = 0;
  583. $iPrev = -1;
  584. foreach ($qresult as $qrow)
  585. {
  586. $qrow = $qrow->attributes;
  587. if ($gid == $qrow['gid']) {$iPrev = $i - 1;}
  588. $i += 1;
  589. }
  590. if ($iPrev >= 0) {$GidPrev = $qresult[$iPrev]->gid;}
  591. else {$GidPrev = "";}
  592. return $GidPrev;
  593. }
  594. /**
  595. * getQidPrevious() returns the Qid of the question prior to the current active question
  596. *
  597. * @param string $surveyid
  598. * @param string $gid
  599. * @param string $qid
  600. *
  601. * @return This Qid of the previous question
  602. */
  603. function getQidPrevious($surveyid, $gid, $qid)
  604. {
  605. $clang = Yii::app()->lang;
  606. $s_lang = Survey::model()->findByPk($surveyid)->language;
  607. $qrows = Questions::model()->findAllByAttributes(array('gid' => $gid, 'sid' => $surveyid, 'language' => $s_lang, 'parent_qid'=>0),array('order'=>'question_order'));
  608. $i = 0;
  609. $iPrev = -1;
  610. if (count($qrows) > 0)
  611. {
  612. foreach ($qrows as $qrow)
  613. {
  614. $qrow = $qrow->attributes;
  615. if ($qid == $qrow['qid']) {$iPrev = $i - 1;}
  616. $i += 1;
  617. }
  618. }
  619. if ($iPrev >= 0) {$QidPrev = $qrows[$iPrev]->qid;}
  620. else {$QidPrev = "";}
  621. return $QidPrev;
  622. }
  623. /**
  624. * getGidNext() returns the Gid of the group next to the current active group
  625. *
  626. * @param string $surveyid
  627. * @param string $gid
  628. *
  629. * @return The Gid of the next group
  630. */
  631. function getGidNext($surveyid, $gid)
  632. {
  633. $clang = Yii::app()->lang;
  634. if (!$surveyid) {$surveyid=returnGlobal('sid');}
  635. $s_lang = Survey::model()->findByPk($surveyid)->language;
  636. //$gquery = "SELECT gid FROM ".db_table_name('groups')." WHERE sid=$surveyid AND language='{$s_lang}' ORDER BY group_order";
  637. $qresult = Groups::model()->findAllByAttributes(array('sid' => $surveyid, 'language' => $s_lang), array('order'=>'group_order'));
  638. $GidNext="";
  639. $i = 0;
  640. $iNext = 1;
  641. foreach ($qresult as $qrow)
  642. {
  643. $qrow = $qrow->attributes;
  644. if ($gid == $qrow['gid']) {$iNext = $i + 1;}
  645. $i += 1;
  646. }
  647. if ($iNext < count($qresult)) {$GidNext = $qresult[$iNext]->gid;}
  648. else {$GidNext = "";}
  649. return $GidNext;
  650. }
  651. /**
  652. * getQidNext() returns the Qid of the question prior to the current active question
  653. *
  654. * @param string $surveyid
  655. * @param string $gid
  656. * @param string $qid
  657. *
  658. * @return This Qid of the previous question
  659. */
  660. function getQidNext($surveyid, $gid, $qid)
  661. {
  662. $clang = Yii::app()->lang;
  663. $s_lang = Survey::model()->findByPk($surveyid)->language;
  664. $qrows = Questions::model()->findAllByAttributes(array('gid' => $gid, 'sid' => $surveyid, 'language' => $s_lang, 'parent_qid' => 0), array('order'=>'question_order'));
  665. $i = 0;
  666. $iNext = 1;
  667. if (count($qrows) > 0)
  668. {
  669. foreach ($qrows as $qrow)
  670. {
  671. if ($qid == $qrow->qid) {$iNext = $i + 1;}
  672. $i += 1;
  673. }
  674. }
  675. if ($iNext < count($qrows)) {$QidNext = $qrows[$iNext]->qid;}
  676. else {$QidNext = "";}
  677. return $QidNext;
  678. }
  679. function convertGETtoPOST($url)
  680. {
  681. $url = preg_replace('/&amp;/i','&',$url);
  682. $stack = explode('?',$url);
  683. $calledscript = array_shift($stack);
  684. $query = array_shift($stack);
  685. $aqueryitems = explode('&',$query);
  686. $arrayParam = Array();
  687. $arrayVal = Array();
  688. foreach ($aqueryitems as $queryitem)
  689. {
  690. $stack = explode ('=', $queryitem);
  691. $paramname = array_shift($stack);
  692. $value = array_shift($stack);
  693. $arrayParam[] = "'".$paramname."'";
  694. $arrayVal[] = substr($value, 0, 9) != "document." ? "'".$value."'" : $value;
  695. }
  696. // $Paramlist = "[" . implode(",",$arrayParam) . "]";
  697. // $Valuelist = "[" . implode(",",$arrayVal) . "]";
  698. $Paramlist = "new Array(" . implode(",",$arrayParam) . ")";
  699. $Valuelist = "new Array(" . implode(",",$arrayVal) . ")";
  700. $callscript = "sendPost('$calledscript','',$Paramlist,$Valuelist);";
  701. return $callscript;
  702. }
  703. /**
  704. * This function calculates how much space is actually used by all files uploaded
  705. * using the File Upload question type
  706. *
  707. * @returns integer Actual space used in MB
  708. */
  709. function calculateTotalFileUploadUsage(){
  710. global $uploaddir;
  711. $sQuery='select sid from {{surveys}}';
  712. $oResult = dbExecuteAssoc($sQuery); //checked
  713. $aRows = $oResult->readAll();
  714. $iTotalSize=0.0;
  715. foreach ($aRows as $aRow)
  716. {
  717. $sFilesPath=$uploaddir.'/surveys/'.$aRow['sid'].'/files';
  718. if (file_exists($sFilesPath))
  719. {
  720. $iTotalSize+=(float)getDirectorySize($sFilesPath);
  721. }
  722. }
  723. return (float)$iTotalSize/1024/1024;
  724. }
  725. function getDirectorySize($directory) {
  726. $size = 0;
  727. foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file){
  728. $size+=$file->getSize();
  729. }
  730. return $size;
  731. }
  732. /**
  733. * Gets number of groups inside a particular survey
  734. *
  735. * @param string $surveyid
  736. * @param mixed $lang
  737. */
  738. function getGroupSum($surveyid, $lang)
  739. {
  740. //$condn = "WHERE sid=".$surveyid." AND language='".$lang."'"; //Getting a count of questions for this survey
  741. $condn = array('sid'=>$surveyid,'language'=>$lang);
  742. $sumresult3 = count(Groups::model()->findAllByAttributes($condn)); //Checked)
  743. return $sumresult3 ;
  744. }
  745. /**
  746. * getMaxGroupOrder($surveyid) queries the database for the maximum sortorder of a group and returns the next higher one.
  747. *
  748. * @param mixed $surveyid
  749. */
  750. function getMaxGroupOrder($surveyid)
  751. {
  752. $s_lang = Survey::model()->findByPk($surveyid)->language;
  753. //$max_sql = "SELECT max( group_order ) AS max FROM ".db_table_name('groups')." WHERE sid =$surveyid AND language='{$s_lang}'" ;
  754. $query = Groups::model()->find(array('order' => 'group_order desc'));
  755. $current_max = !is_null($query) ? $query->group_order : '';
  756. if($current_max!="")
  757. {
  758. return ++$current_max ;
  759. }
  760. else return "0" ;
  761. }
  762. /**
  763. * getGroupOrder($surveyid,$gid) queries the database for the sortorder of a group.
  764. *
  765. * @param mixed $surveyid
  766. * @param mixed $gid
  767. * @return mixed
  768. */
  769. function getGroupOrder($surveyid,$gid)
  770. {
  771. $s_lang = Survey::model()->findByPk($surveyid)->language;
  772. //$grporder_sql = "SELECT group_order FROM ".db_table_name('groups')." WHERE sid =$surveyid AND language='{$s_lang}' AND gid=$gid" ;
  773. $grporder_result = Groups::model()->findByAttributes(array('sid' => $surveyid, 'gid' => $gid, 'language' => $s_lang)); //Checked
  774. $grporder_row = $grporder_result->attributes ;
  775. $group_order = $grporder_row['group_order'];
  776. if($group_order=="")
  777. {
  778. return "0" ;
  779. }
  780. else return $group_order ;
  781. }
  782. /**
  783. * getMaxQuestionOrder($gid) queries the database for the maximum sortorder of a question.
  784. *
  785. */
  786. function getMaxQuestionOrder($gid,$surveyid)
  787. {
  788. $gid=sanitize_int($gid);
  789. $s_lang = Survey::model()->findByPk($surveyid)->language;
  790. $max_sql = "SELECT max( question_order ) AS max FROM {{questions}} WHERE gid='$gid' AND language='$s_lang'";
  791. $max_result = Yii::app()->db->createCommand($max_sql)->query(); //Checked
  792. $maxrow = $max_result->read() ;
  793. $current_max = $maxrow['max'];
  794. if($current_max=="")
  795. {
  796. return "0" ;
  797. }
  798. else return $current_max ;
  799. }
  800. /**
  801. * getQuestionClass() returns a class name for a given question type to allow custom styling for each question type.
  802. *
  803. * @param string $input containing unique character representing each question type.
  804. * @return string containing the class name for a given question type.
  805. */
  806. function getQuestionClass($input)
  807. {
  808. switch($input)
  809. { // I think this is a bad solution to adding classes to question
  810. // DIVs but I can't think of a better solution. (eric_t_cruiser)
  811. case 'X': return 'boilerplate'; // BOILERPLATE QUESTION
  812. case '5': return 'choice-5-pt-radio'; // 5 POINT CHOICE radio-buttons
  813. case 'D': return 'date'; // DATE
  814. case 'Z': return 'list-radio-flexible'; // LIST Flexible radio-button
  815. case 'L': return 'list-radio'; // LIST radio-button
  816. case 'W': return 'list-dropdown-flexible'; // LIST drop-down (flexible label)
  817. case '!': return 'list-dropdown'; // List - dropdown
  818. case 'O': return 'list-with-comment'; // LIST radio-button + textarea
  819. case 'R': return 'ranking'; // RANKING STYLE
  820. case 'M': return 'multiple-opt'; // Multiple choice checkbox
  821. case 'I': return 'language'; // Language Question
  822. case 'P': return 'multiple-opt-comments'; // Multiple choice with comments checkbox + text
  823. case 'Q': return 'multiple-short-txt'; // TEXT
  824. case 'K': return 'numeric-multi'; // MULTIPLE NUMERICAL QUESTION
  825. case 'N': return 'numeric'; // NUMERICAL QUESTION TYPE
  826. case 'S': return 'text-short'; // SHORT FREE TEXT
  827. case 'T': return 'text-long'; // LONG FREE TEXT
  828. case 'U': return 'text-huge'; // HUGE FREE TEXT
  829. case 'Y': return 'yes-no'; // YES/NO radio-buttons
  830. case 'G': return 'gender'; // GENDER drop-down list
  831. case 'A': return 'array-5-pt'; // ARRAY (5 POINT CHOICE) radio-buttons
  832. case 'B': return 'array-10-pt'; // ARRAY (10 POINT CHOICE) radio-buttons
  833. case 'C': return 'array-yes-uncertain-no'; // ARRAY (YES/UNCERTAIN/NO) radio-buttons
  834. case 'E': return 'array-increase-same-decrease'; // ARRAY (Increase/Same/Decrease) radio-buttons
  835. case 'F': return 'array-flexible-row'; // ARRAY (Flexible) - Row Format
  836. case 'H': return 'array-flexible-column'; // ARRAY (Flexible) - Column Format
  837. // case '^': return 'slider'; // SLIDER CONTROL
  838. case ':': return 'array-multi-flexi'; // ARRAY (Multi Flexi) 1 to 10
  839. case ";": return 'array-multi-flexi-text';
  840. case "1": return 'array-flexible-duel-scale'; // Array dual scale
  841. case "*": return 'equation'; // Equation
  842. default: return 'generic_question'; // Should have a default fallback
  843. };
  844. };
  845. /**
  846. * setupColumns() defines all the html tags to be wrapped around
  847. * various list type answers.
  848. *
  849. * @param integer $columns - the number of columns, usually supplied by $dcols
  850. * @param integer $answer_count - the number of answers to a question, usually supplied by $anscount
  851. * @param string $wrapperclass - a global class for the wrapper
  852. * @param string $itemclass - a class for the item
  853. * @return array with all the various opening and closing tags to generate a set of columns.
  854. *
  855. * It returns an array with the following items:
  856. * $wrapper['whole-start'] = Opening wrapper for the whole list
  857. * $wrapper['whole-end'] = closing wrapper for the whole list
  858. * $wrapper['col-devide'] = normal column devider
  859. * $wrapper['col-devide-last'] = the last column devider (to allow
  860. * for different styling of the last
  861. * column
  862. * $wrapper['item-start'] = opening wrapper tag for individual
  863. * option
  864. * $wrapper['item-start-other'] = opening wrapper tag for other
  865. * option
  866. * $wrapper['item-start-noanswer'] = opening wrapper tag for no answer
  867. * option
  868. * $wrapper['item-end'] = closing wrapper tag for individual
  869. * option
  870. * $wrapper['maxrows'] = maximum number of rows in each
  871. * column
  872. * $wrapper['cols'] = Number of columns to be inserted
  873. * (and checked against)
  874. *
  875. *
  876. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  877. * Columns are a problem.
  878. * Really there is no perfect solution to columns at the moment.
  879. *
  880. * - Using Tables is problematic semanticly.
  881. * - Using inline or float to create columns, causes the answers
  882. * flows horizontally, not vertically which is not ideal visually.
  883. * - Using CSS3 columns is also a problem because of browser support
  884. * and also because if you have answeres split across two or more
  885. * lines, and those answeres happen to fall at the bottom of a
  886. * column, the answer might be split across columns as well as
  887. * lines.
  888. * - Using nested unordered list with the first level of <LI>s
  889. * floated is the same as using tables and so is bad semantically
  890. * for the same reason tables are bad.
  891. * - Breaking the unordered lists into consecutive floated unordered
  892. * lists is not great semantically but probably not as bad as
  893. * using tables.
  894. *
  895. * Because I haven't been able to decide which option is the least
  896. * bad, I have handed over that responsibility to the admin who sets
  897. * LimeSurvey up on their server.
  898. *
  899. * There are four options:
  900. * 'css' using one of the various CSS only methods for
  901. * rendering columns.
  902. * (Check the CSS file for your chosen template to see
  903. * how columns are defined.)
  904. * 'ul' using multiple floated unordered lists. (DEFAULT)
  905. * 'table' using conventional tables based layout.
  906. * NULL blocks the use of columns
  907. *
  908. * 'ul' is the default because it's the best possible compromise
  909. * between semantic markup and visual layout.
  910. */
  911. function setupColumns($columns, $answer_count,$wrapperclass="",$itemclass="")
  912. {
  913. $column_style = Yii::app()->getConfig('column_style');
  914. if ( !in_array($column_style,array('css','ul','table')) && !is_null($column_style) )
  915. {
  916. $column_style = 'ul';
  917. };
  918. if($columns < 2)
  919. {
  920. $column_style = null;
  921. $columns = 1;
  922. }
  923. if(($columns > $answer_count) && $answer_count>0)
  924. {
  925. $columns = $answer_count;
  926. };
  927. $class_first = ' class="'.$wrapperclass.'"';
  928. if($columns > 1 && !is_null($column_style))
  929. {
  930. if($column_style == 'ul')
  931. {
  932. $ul = '-ul';
  933. }
  934. else
  935. {
  936. $ul = '';
  937. }
  938. $class_first = ' class="'.$wrapperclass.' cols-'.$columns . $ul.' first"';
  939. $class = ' class="'.$wrapperclass.' cols-'.$columns . $ul.'"';
  940. $class_last_ul = ' class="'.$wrapperclass.' cols-'.$columns . $ul.' last"';
  941. $class_last_table = ' class="'.$wrapperclass.' cols-'.$columns.' last"';
  942. }
  943. else
  944. {
  945. $class = ' class="'.$wrapperclass.'"';
  946. $class_last_ul = ' class="'.$wrapperclass.'"';
  947. $class_last_table = ' class="'.$wrapperclass.'"';
  948. };
  949. $wrapper = array(
  950. 'whole-start' => "\n<ul$class_first>\n"
  951. ,'whole-end' => "</ul>\n"
  952. ,'col-devide' => ''
  953. ,'col-devide-last' => ''
  954. ,'item-start' => "\t<li class=\"{$itemclass}\">\n"
  955. ,'item-start-other' => "\t<li class=\"{$itemclass} other other-item\">\n"
  956. ,'item-start-noanswer' => "\t<li class=\"{$itemclass} noanswer-item\">\n"
  957. ,'item-end' => "\t</li>\n"
  958. ,'maxrows' => ceil($answer_count/$columns) //Always rounds up to nearest whole number
  959. ,'cols' => $columns
  960. );
  961. switch($column_style)
  962. {
  963. case 'ul': if($columns > 1)
  964. {
  965. $wrapper['col-devide'] = "\n</ul>\n\n<ul$class>\n";
  966. $wrapper['col-devide-last'] = "\n</ul>\n\n<ul$class_last_ul>\n";
  967. }
  968. break;
  969. case 'table': $table_cols = '';
  970. for($cols = $columns ; $cols > 0 ; --$cols)
  971. {
  972. switch($cols)
  973. {
  974. case $columns: $table_cols .= "\t<col$class_first />\n";
  975. break;
  976. case 1: $table_cols .= "\t<col$class_last_table />\n";
  977. break;
  978. default: $table_cols .= "\t<col$class />\n";
  979. };
  980. };
  981. if($columns > 1)
  982. {
  983. $wrapper['col-devide'] = "\t</ul>\n</td>\n\n<td>\n\t<ul>\n";
  984. $wrapper['col-devide-last'] = "\t</ul>\n</td>\n\n<td class=\"last\">\n\t<ul>\n";
  985. };
  986. $wrapper['whole-start'] = "\n<table$class>\n$table_cols\n\t<tbody>\n<tr>\n<td>\n\t<ul>\n";
  987. $wrapper['whole-end'] = "\t</ul>\n</td>\n</tr>\n\t</tbody>\n</table>\n";
  988. $wrapper['item-start'] = "<li class=\"{$itemclass}\">\n";
  989. $wrapper['item-end'] = "</li class=\"{$itemclass}\">\n";
  990. };
  991. return $wrapper;
  992. };
  993. function alternation($alternate = '' , $type = 'col')
  994. {
  995. /**
  996. * alternation() Returns a class identifyer for alternating between
  997. * two options. Used to style alternate elements differently. creates
  998. * or alternates between the odd string and the even string used in
  999. * as column and row classes for array type questions.
  1000. *
  1001. * @param string $alternate = '' (empty) (default) , 'array2' , 'array1' , 'odd' , 'even'
  1002. * @param string $type = 'col' (default) or 'row'
  1003. *
  1004. * @return string representing either the first alternation or the opposite alternation to the one supplied..
  1005. */
  1006. /*
  1007. // The following allows type to be left blank for row in subsequent
  1008. // function calls.
  1009. // It has been left out because 'row' must be defined the first time
  1010. // alternation() is called. Since it is only ever written once for each
  1011. // while statement within a function, 'row' is always defined.
  1012. if(!empty($alternate) && $type != 'row')
  1013. { if($alternate == ('array2' || 'array1'))
  1014. {
  1015. $type = 'row';
  1016. };
  1017. };
  1018. // It has been left in case it becomes useful but probably should be
  1019. // removed.
  1020. */
  1021. if($type == 'row')
  1022. {
  1023. $odd = 'array2'; // should be row_odd
  1024. $even = 'array1'; // should be row_even
  1025. }
  1026. else
  1027. {
  1028. $odd = 'odd'; // should be col_odd
  1029. $even = 'even'; // should be col_even
  1030. };
  1031. if($alternate == $odd)
  1032. {
  1033. $alternate = $even;
  1034. }
  1035. else
  1036. {
  1037. $alternate = $odd;
  1038. };
  1039. return $alternate;
  1040. }
  1041. /**
  1042. * longestString() returns the length of the longest string past to it.
  1043. * @peram string $new_string
  1044. * @peram integer $longest_length length of the (previously) longest string passed to it.
  1045. * @return integer representing the length of the longest string passed (updated if $new_string was longer than $longest_length)
  1046. *
  1047. * usage should look like this: $longest_length = longestString( $new_string , $longest_length );
  1048. *
  1049. */
  1050. function longestString( $new_string , $longest_length )
  1051. {
  1052. if($longest_length < strlen(trim(strip_tags($new_string))))
  1053. {
  1054. $longest_length = strlen(trim(strip_tags($new_string)));
  1055. };
  1056. return $longest_length;
  1057. };
  1058. /**
  1059. * getNotificationList() returns different options for notifications
  1060. *
  1061. * @param string $notificationcode - the currently selected one
  1062. *
  1063. * @return This string is returned containing <option></option> formatted list of notification methods for current survey
  1064. */
  1065. function getNotificationList($notificationcode)
  1066. {
  1067. $clang = Yii::app()->lang;
  1068. $ntypes = array(
  1069. "0"=>$clang->gT("No email notification"),
  1070. "1"=>$clang->gT("Basic email notification"),
  1071. "2"=>$clang->gT("Detailed email notification with result codes")
  1072. );
  1073. if (!isset($ntypeselector)) {$ntypeselector="";}
  1074. foreach($ntypes as $ntcode=>$ntdescription)
  1075. {
  1076. $ntypeselector .= "<option value='$ntcode'";
  1077. if ($notificationcode == $ntcode) {$ntypeselector .= " selected='selected'";}
  1078. $ntypeselector .= ">$ntdescription</option>\n";
  1079. }
  1080. return $ntypeselector;
  1081. }
  1082. /**
  1083. * getGroupList() queries the database for a list of all groups matching the current survey sid
  1084. *
  1085. *
  1086. * @param string $gid - the currently selected gid/group
  1087. *
  1088. * @return This string is returned containing <option></option> formatted list of groups to current survey
  1089. */
  1090. function getGroupList($gid,$surveyid)
  1091. {
  1092. $clang = Yii::app()->lang;
  1093. $groupselecter="";
  1094. $gid=sanitize_int($gid);
  1095. $surveyid=sanitize_int($surveyid);
  1096. if (!$surveyid) {$surveyid=returnGlobal('sid');}
  1097. $s_lang = Survey::model()->findByPk($surveyid)->language;
  1098. $gidquery = "SELECT gid, group_name FROM {{groups}} WHERE sid='{$surveyid}' AND language='{$s_lang}' ORDER BY group_order";
  1099. $gidresult = Yii::app()->db->createCommand($gidquery)->query(); //Checked
  1100. foreach ($gidresult->readAll() as $gv)
  1101. {
  1102. $groupselecter .= "<option";
  1103. if ($gv['gid'] == $gid) {$groupselecter .= " selected='selected'"; $gvexist = 1;}
  1104. $groupselecter .= " value='".Yii::app()->getConfig('scriptname')."?sid=$surveyid&amp;gid=".$gv['gid']."'>".htmlspecialchars($gv['group_name'])."</option>\n";
  1105. }
  1106. if ($groupselecter)
  1107. {
  1108. if (!isset($gvexist)) {$groupselecter = "<option selected='selected'>".$clang->gT("Please choose...")."</option>\n".$groupselecter;}
  1109. else {$groupselecter .= "<option value='".Yii::app()->getConfig('scriptname')."?sid=$surveyid&amp;gid='>".$clang->gT("None")."</option>\n";}
  1110. }
  1111. return $groupselecter;
  1112. }
  1113. function getGroupList3($gid,$surveyid)
  1114. {
  1115. //$clang = Yii::app()->lang;
  1116. $gid=sanitize_int($gid);
  1117. $surveyid=sanitize_int($surveyid);
  1118. if (!$surveyid) {$surveyid=returnGlobal('sid');}
  1119. $groupselecter = "";
  1120. $s_lang = Survey::model()->findByPk($surveyid)->language;
  1121. //$gidquery = "SELECT gid, group_name FROM ".db_table_name('groups')." WHERE sid=$surveyid AND language='{$s_lang}' ORDER BY group_order";
  1122. $gidresult = Groups::model()->findAllByAttributes(array('sid' => $surveyid, 'language' => $s_lang), array('order'=>'group_order'));
  1123. foreach ($gidresult as $gv)
  1124. {
  1125. $gv = $gv->attributes;
  1126. $groupselecter .= "<option";
  1127. if ($gv['gid'] == $gid) {$groupselecter .= " selected='selected'"; }
  1128. $groupselecter .= " value='".$gv['gid']."'>".htmlspecialchars($gv['group_name'])."</option>\n";
  1129. }
  1130. return $groupselecter;
  1131. }
  1132. /**
  1133. * put your comment there...
  1134. *
  1135. * @param mixed $gid
  1136. * @param mixed $language
  1137. */
  1138. function getGroupListLang($gid, $language, $surveyid)
  1139. {
  1140. $clang = Yii::app()->lang;
  1141. $groupselecter="";
  1142. if (!$surveyid) {$surveyid=returnGlobal('sid');}
  1143. $gidresult = Groups::model()->findAll(array('condition'=>'sid=:surveyid AND language=:language',
  1144. 'order'=>'group_order',
  1145. 'params'=>array(':surveyid'=>$surveyid,':language'=>$language))); //Checked)
  1146. foreach ($gidresult as $gv)
  1147. {
  1148. $gv = $gv->attributes;
  1149. $groupselecter .= "<option";
  1150. if ($gv['gid'] == $gid) {$groupselecter .= " selected='selected'"; $gvexist = 1;}
  1151. $link = Yii::app()->getController()->createUrl("/admin/survey/sa/view/surveyid/".$surveyid."/gid/".$gv['gid']);
  1152. $groupselecter .= " value='{$link}'>";
  1153. if (strip_tags($gv['group_name']))
  1154. {
  1155. $groupselecter .= htmlspecialchars(strip_tags($gv['group_name']));
  1156. } else {
  1157. $groupselecter .= htmlspecialchars($gv['group_name']);
  1158. }
  1159. $groupselecter .= "</option>\n";
  1160. }
  1161. if ($groupselecter)
  1162. {
  1163. $link = Yii::app()->getController()->createUrl("/admin/survey/sa/view/surveyid/".$surveyid);
  1164. if (!isset($gvexist)) {$groupselecter = "<option selected='selected'>".$clang->gT("Please choose...")."</option>\n".$groupselecter;}
  1165. else {$groupselecter .= "<option value='{$link}'>".$clang->gT("None")."</option>\n";}
  1166. }
  1167. return $groupselecter;
  1168. }
  1169. function getUserList($outputformat='fullinfoarray')
  1170. {
  1171. $clang = Yii::app()->lang;
  1172. if (!empty(Yii::app()->session['loginID']))
  1173. {
  1174. $myuid=sanitize_int(Yii::app()->session['loginID']);
  1175. }
  1176. $usercontrolSameGroupPolicy = Yii::app()->getConfig('usercontrolSameGroupPolicy');
  1177. if (Yii::app()->session['USER_RIGHT_SUPERADMIN'] != 1 && isset($usercontrolSameGroupPolicy) &&
  1178. $usercontrolSameGroupPolicy == true)
  1179. {
  1180. if (isset($myuid))
  1181. {
  1182. $sDatabaseType = Yii::app()->db->getDriverName();
  1183. if ($sDatabaseType=='mssql' || $sDatabaseType=="sqlsrv")
  1184. {
  1185. $sSelectFields = 'users_name,uid,email,full_name,parent_id,create_survey,participant_panel,configurator,create_user,delete_user,superadmin,manage_template,manage_label,CAST(password as varchar) as password';
  1186. }
  1187. else
  1188. {
  1189. $sSelectFields = 'users_name,uid,email,full_name,parent_id,create_survey,participant_panel,configurator,create_user,delete_user,superadmin,manage_template,manage_label,password';
  1190. }
  1191. // List users from same group as me + all my childs
  1192. // a subselect is used here because MSSQL does not like to group by text
  1193. // also Postgres does like this one better
  1194. $uquery = " SELECT {$sSelectFields} from {{users}} where uid in (
  1195. SELECT uid from {{user_in_groups}} where ugid in (
  1196. SELECT ugid from {{user_in_groups}} where uid={$myuid}
  1197. )
  1198. )
  1199. UNION
  1200. SELECT {$sSelectFields} from {{users}} v where v.parent_id={$myuid}
  1201. UNION
  1202. SELECT {$sSelectFields} from {{users}} v where uid={$myuid}";
  1203. }
  1204. else
  1205. {
  1206. return array(); // Or die maybe
  1207. }
  1208. }
  1209. else
  1210. {
  1211. $uquery = "SELECT * FROM {{users}} ORDER BY uid";
  1212. }
  1213. $uresult = Yii::app()->db->createCommand($uquery)->query()->readAll(); //Checked
  1214. if (count($uresult)==0)
  1215. //user is not in a group and usercontrolSameGroupPolicy is activated - at least show his own userinfo
  1216. {
  1217. $uquery = "SELECT u.* FROM {{users}} AS u WHERE u.uid=".$myuid;
  1218. $uresult = Yii::app()->db->createCommand($uquery)->query()->readAll();//Checked
  1219. }
  1220. $userlist = array();
  1221. $userlist[0] = "Reserved for logged in user";
  1222. //while ($srow = $uresult->readAll())
  1223. foreach ($uresult as $srow)
  1224. {
  1225. if ($outputformat != 'onlyuidarray')
  1226. {
  1227. if ($srow['uid'] != Yii::app()->session['loginID'])
  1228. {
  1229. $userlist[] = array("user"=>$srow['users_name'], "uid"=>$srow['uid'], "email"=>$srow['email'], "password"=>$srow['password'], "full_name"=>$srow['full_name'], "parent_id"=>$srow['parent_id'], "create_survey"=>$srow['create_survey'], "participant_panel"=>$srow['participant_panel'], "configurator"=>$srow['configurator'], "create_user"=>$srow['create_user'], "delete_user"=>$srow['delete_user'], "superadmin"=>$srow['superadmin'], "manage_template"=>$srow['manage_template'], "manage_label"=>$srow['manage_label']); //added by Dennis modified by Moses
  1230. }
  1231. else
  1232. {
  1233. $userlist[0] = array("user"=>$srow['users_name'], "uid"=>$srow['uid'], "email"=>$srow['email'], "password"=>$srow['password'], "full_name"=>$srow['full_name'], "parent_id"=>$srow['parent_id'], "create_survey"=>$srow['create_survey'],"participant_panel"=>$srow['participant_panel'], "configurator"=>$srow['configurator'], "create_user"=>$srow['create_user'], "delete_user"=>$srow['delete_user'], "superadmin"=>$srow['superadmin'], "manage_template"=>$srow['manage_template'], "manage_label"=>$srow['manage_label']);
  1234. }
  1235. }
  1236. else
  1237. {
  1238. if ($srow['uid'] != Yii::app()->session['loginID'])
  1239. {
  1240. $userlist[] = $srow['uid'];
  1241. }
  1242. else
  1243. {
  1244. $userlist[0] = $srow['uid'];
  1245. }
  1246. }
  1247. }
  1248. return $userlist;
  1249. }
  1250. /**
  1251. * Gets all survey infos in one big array including the language specific settings
  1252. *
  1253. * @param string $surveyid The survey ID
  1254. * @param string $languagecode The language code - if not given the base language of the particular survey is used
  1255. * @return array Returns array with survey info or false, if survey does not exist
  1256. */
  1257. function getSurveyInfo($surveyid, $languagecode='')
  1258. {
  1259. static $staticSurveyInfo = array();// Use some static
  1260. $surveyid=sanitize_int($surveyid);
  1261. $languagecode=sanitize_languagecode($languagecode);
  1262. $thissurvey=false;
  1263. // Do job only if this survey exist
  1264. if(!Survey::model()->findByPk($surveyid))
  1265. {
  1266. return false;
  1267. }
  1268. // if no language code is set then get the base language one
  1269. if ((!isset($languagecode) || $languagecode==''))
  1270. {
  1271. $languagecode=Survey::model()->findByPk($surveyid)->language;
  1272. }
  1273. if(isset($staticSurveyInfo[$surveyid][$languagecode]) )
  1274. {
  1275. $thissurvey=$staticSurveyInfo[$surveyid][$languagecode];
  1276. }
  1277. else
  1278. {
  1279. $result = Surveys_languagesettings::model()->with('survey')->findByPk(array('surveyls_survey_id' => $surveyid, 'surveyls_language' => $languagecode));
  1280. if (is_null($result)) {
  1281. // When additional language was added, but not saved it does not exists
  1282. // We should revert to the bas…

Large files files are truncated, but you can click here to view the full file