PageRenderTime 53ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/sondage/admin/remotecontrol/lsrc.helper.php

https://bitbucket.org/bontiv/insomnia
PHP | 2460 lines | 1837 code | 257 blank | 366 comment | 219 complexity | c7a88cb41d6052a07b3daa35dad8658a MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0, LGPL-2.1, GPL-3.0, BSD-3-Clause, GPL-2.0

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

  1. <?php
  2. /*
  3. * LimeSurvey
  4. * Copyright (C) 2007 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. * $Id: lsrc.helper.php 9656 2011-01-07 20:48:39Z c_schmitz $
  14. *
  15. */
  16. /**
  17. * @author Wahrendorff
  18. *
  19. */
  20. class LsrcHelper {
  21. /**
  22. * simple debug function to make life a bit easier
  23. *
  24. * @param string $text
  25. */
  26. function debugLsrc($text)
  27. {
  28. include("lsrc.config.php");
  29. if($lsrcDebug)
  30. {
  31. error_log("\n".date("Y-m-d H:i:s")." ".$text, 3 , $lsrcDebugLog);
  32. }
  33. return;
  34. }
  35. /**
  36. * function to get the id of the surveyowner
  37. *
  38. * @param unknown_type $iVid
  39. * @return unknown
  40. */
  41. function getSurveyOwner($iVid)
  42. {
  43. global $connect ;
  44. global $dbprefix ;
  45. $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
  46. include("lsrc.config.php");
  47. //$this= new LsrcHelper();
  48. if($this->surveyExists($iVid))
  49. {
  50. $query2num = "SELECT owner_id FROM {$dbprefix}surveys WHERE sid=".sanitize_int($iVid)."";
  51. $rs = db_execute_assoc($query2num);
  52. $field=$rs->FetchRow();
  53. return $field['owner_id'];
  54. }else{return false;}
  55. }
  56. /**
  57. * This function changes data in LS-DB, its very sensitive, because every table can be changed.
  58. *
  59. * @param unknown_type $table
  60. * @param unknown_type $key
  61. * @param unknown_type $value
  62. * @param unknown_type $where
  63. * @return String
  64. */
  65. function changeTable($table, $key, $value, $where, $mode='0')//XXX
  66. {//be aware that this function may be a security risk
  67. global $connect ;
  68. global $dbprefix ;
  69. $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
  70. include("lsrc.config.php");
  71. if($mode=='' || !isset($mode) || $mode=='0')
  72. {
  73. $where = str_replace("\\","",$where);
  74. $query2num = "SELECT {$key} FROM {$dbprefix}{$table} WHERE {$where}";
  75. $rs = db_execute_assoc($query2num);
  76. $this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", OK ($query2num)");
  77. $query2update = "update ".$dbprefix.$table." set ".$key."='".$value."' where ".$where."";
  78. $this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", OK ($query2update)");
  79. if($connect->Execute($query2update)){
  80. return $rs->RecordCount()." Rows changed";
  81. }
  82. else{
  83. return "nothing changed";
  84. }
  85. }
  86. if($mode==1 || $mode=='1')
  87. {
  88. $query2insert = "INSERT INTO {$dbprefix}{$table} ({$key}) VALUES ({$value});";
  89. $this->debugLsrc("wir sind in Line ".__LINE__.", inserting ($query2insert)");
  90. if($connect->Execute($query2insert))
  91. {
  92. $this->debugLsrc("wir sind in Line ".__LINE__.", inserting OK");
  93. return true;
  94. }
  95. else
  96. {
  97. return false;
  98. }
  99. }
  100. }
  101. /**
  102. *
  103. * Enter description here...
  104. * @param $surveyid
  105. * @param $type
  106. * @param $maxLsrcEmails
  107. * @return unknown_type
  108. */
  109. function emailSender($surveyid, $type, $maxLsrcEmails='') //XXX
  110. {
  111. global $publicurl,$maxemails;
  112. global $connect,$sitename ;
  113. global $dbprefix ;
  114. $surveyid = sanitize_int($surveyid);
  115. include("lsrc.config.php");
  116. // wenn maxmails ber den lsrc gegeben wird das nutzen, ansonsten die default werte aus der config.php
  117. if($maxLsrcEmails!='')
  118. $maxemails = $maxLsrcEmails;
  119. switch ($type){
  120. case "custom":
  121. break;
  122. case "invite":
  123. $this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", START invite ");
  124. if(isset($surveyid) && getEmailFormat($surveyid) == 'html')
  125. {
  126. $ishtml=true;
  127. }
  128. else
  129. {
  130. $ishtml=false;
  131. }
  132. //$tokenoutput .= ("Sending Invitations");
  133. //if (isset($tokenid)) {$tokenoutput .= " (".("Sending to Token ID").":&nbsp;{$tokenid})";}
  134. //$tokenoutput .= "\n";
  135. $this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", $surveyid, $type");
  136. // Texte für Mails aus der Datenbank holen und in die POST Dinger schreiben. Nicht schön aber praktikabel
  137. $sql = "SELECT surveyls_language, surveyls_email_invite_subj, surveyls_email_invite ".
  138. "FROM {$dbprefix}surveys_languagesettings ".
  139. "WHERE surveyls_survey_id = ".$surveyid." ";
  140. //GET SURVEY DETAILS
  141. $thissurvey=getSurveyInfo($surveyid);
  142. // $connect->SetFetchMode(ADODB_FETCH_ASSOC);
  143. // $sqlResult=$connect->Execute($sql);
  144. $sqlResult = db_execute_assoc($sql);
  145. $this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", invite ");
  146. while($languageRow = $sqlResult->FetchRow())
  147. {
  148. $_POST['message_'.$languageRow['surveyls_language']] = $languageRow['surveyls_email_invite'];
  149. $_POST['subject_'.$languageRow['surveyls_language']] = $languageRow['surveyls_email_invite_subj'];
  150. }
  151. // if (isset($_POST['bypassbademails']) && $_POST['bypassbademails'] == 'Y')
  152. // {
  153. // $SQLemailstatuscondition = " AND emailstatus = 'OK'";
  154. // }
  155. // else
  156. // {
  157. // $SQLemailstatuscondition = "";
  158. // }
  159. $this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", invite ");
  160. $ctquery = "SELECT * FROM ".db_table_name("tokens_{$surveyid}")." WHERE ((completed ='N') or (completed='')) AND ((sent ='N') or (sent='')) AND emailstatus = 'OK' ";
  161. if (isset($tokenid)) {$ctquery .= " AND tid='{$tokenid}'";}
  162. //$tokenoutput .= "<!-- ctquery: $ctquery -->\n";
  163. $ctresult = $connect->Execute($ctquery);
  164. $ctcount = $ctresult->RecordCount();
  165. $ctfieldcount = $ctresult->FieldCount();
  166. $emquery = "SELECT * ";
  167. //if ($ctfieldcount > 7) {$emquery .= ", attribute_1, attribute_2";}
  168. $this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", invite ");
  169. $emquery .= " FROM ".db_table_name("tokens_{$surveyid}")." WHERE ((completed ='N') or (completed='')) AND ((sent ='N') or (sent='')) AND emailstatus = 'OK' ";
  170. if (isset($tokenid)) {$emquery .= " and tid='{$tokenid}'";}
  171. //$tokenoutput .= "\n\n<!-- emquery: $emquery -->\n\n";
  172. $emresult = db_select_limit_assoc($emquery,$maxemails);
  173. $emcount = $emresult->RecordCount();
  174. //$tokenoutput .= "<table width='500px' align='center' >\n"
  175. ////."\t<tr>\n"
  176. //."\t\t<td><font size='1'>\n";
  177. $surveylangs = GetAdditionalLanguagesFromSurveyID($surveyid);
  178. $baselanguage = GetBaseLanguageFromSurveyID($surveyid);
  179. array_unshift($surveylangs,$baselanguage);
  180. $this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", invite ");
  181. foreach ($surveylangs as $language)
  182. {
  183. $_POST['message_'.$language]=auto_unescape($_POST['message_'.$language]);
  184. $_POST['subject_'.$language]=auto_unescape($_POST['subject_'.$language]);
  185. if ($ishtml) $_POST['message_'.$language] = html_entity_decode($_POST['message_'.$language], ENT_QUOTES, $emailcharset);
  186. }
  187. $this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", invite ");
  188. if ($emcount > 0)
  189. {
  190. $mailsSend = 0;
  191. while ($emrow = $emresult->FetchRow())
  192. {
  193. $c=1;
  194. unset($fieldsarray);
  195. $to = $emrow['email'];
  196. $fieldsarray["{EMAIL}"]=$emrow['email'];
  197. $fieldsarray["{FIRSTNAME}"]=$emrow['firstname'];
  198. $fieldsarray["{LASTNAME}"]=$emrow['lastname'];
  199. $fieldsarray["{TOKEN}"]=$emrow['token'];
  200. $fieldsarray["{LANGUAGE}"]=$emrow['language'];
  201. while(isset($emrow["attribute_$c"]))
  202. {
  203. $fieldsarray["{ATTRIBUTE_$c}"]=$emrow["attribute_$c"];
  204. ++$c;
  205. }
  206. $fieldsarray["{ADMINNAME}"]= $thissurvey['adminname'];
  207. $fieldsarray["{ADMINEMAIL}"]=$thissurvey['adminemail'];
  208. $fieldsarray["{SURVEYNAME}"]=$thissurvey['name'];
  209. $fieldsarray["{SURVEYDESCRIPTION}"]=$thissurvey['description'];
  210. $fieldsarray["{EXPIRY}"]=$thissurvey["expiry"];
  211. $emrow['language']=trim($emrow['language']);
  212. if ($emrow['language']=='') {$emrow['language']=$baselanguage;} //if language is not give use default
  213. $found = array_search($emrow['language'], $surveylangs);
  214. if ($found==false) {$emrow['language']=$baselanguage;}
  215. $from = $thissurvey['adminemail'];
  216. if ($ishtml === false)
  217. {
  218. if ( $modrewrite )
  219. {
  220. $fieldsarray["{SURVEYURL}"]="$publicurl/$surveyid/lang-".trim($emrow['language'])."/tk-{$emrow['token']}";
  221. }
  222. else
  223. {
  224. $fieldsarray["{SURVEYURL}"]="$publicurl/index.php?lang=".trim($emrow['language'])."&sid=$surveyid&token={$emrow['token']}";
  225. }
  226. }
  227. else
  228. {
  229. if ( $modrewrite )
  230. {
  231. $fieldsarray["{SURVEYURL}"]="<a href='$publicurl/$surveyid/lang-".trim($emrow['language'])."/tk-{$emrow['token']}'>".htmlspecialchars("$publicurl/$surveyid/lang-".trim($emrow['language'])."/tk-{$emrow['token']}")."</a>";
  232. }
  233. else
  234. {
  235. $fieldsarray["{SURVEYURL}"]="<a href='$publicurl/index.php?lang=".trim($emrow['language'])."&sid=$surveyid&token={$emrow['token']}'>".htmlspecialchars("$publicurl/index.php?lang=".trim($emrow['language'])."&sid=$surveyid&token={$emrow['token']}")."</a>";
  236. }
  237. }
  238. $this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", invite ");
  239. $modsubject=Replacefields($_POST['subject_'.$emrow['language']], $fieldsarray);
  240. $modmessage=Replacefields($_POST['message_'.$emrow['language']], $fieldsarray);
  241. if (SendEmailMessage($modmessage, $modsubject, $to , $from, $sitename, $ishtml, getBounceEmail($surveyid)))
  242. {
  243. // Put date into sent
  244. //$timeadjust = 0;
  245. $today = date("Y-m-d H:i");
  246. $this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", invite Today:".$today);
  247. $udequery = "UPDATE ".db_table_name("tokens_{$surveyid}")."\n"
  248. ."SET sent='$today' WHERE tid={$emrow['tid']}";
  249. //
  250. $uderesult = $connect->Execute($udequery);
  251. $mailsSend++;
  252. //$tokenoutput .= "[".("Invitation sent to:")."{$emrow['firstname']} {$emrow['lastname']} ($to)]\n";
  253. }
  254. else
  255. {
  256. //$tokenoutput .= ReplaceFields(("Email to {FIRSTNAME} {LASTNAME} ({EMAIL}) failed. Error Message:")." ".$maildebug."", $fieldsarray);
  257. if($n==1)
  258. $failedAddresses .= ",".$to;
  259. else
  260. {
  261. $failedAddresses = $to;
  262. $n=1;
  263. }
  264. }
  265. }
  266. $this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", invite ");
  267. if ($ctcount > $emcount)
  268. {
  269. $lefttosend = $ctcount-$maxemails;
  270. }else{$lefttosend = 0;}
  271. }
  272. else
  273. {
  274. return "No Mails to send";
  275. }
  276. if($maxemails>0 && $maxemails!='')
  277. {
  278. $returnValue = "".$mailsSend." Mails send. ".$lefttosend." Mails left to send";
  279. if(isset($failedAddresses))
  280. $returnValue .= "\nCould not send to: ".$failedAddresses;
  281. return $returnValue;
  282. }
  283. if(isset($mailsSend))
  284. {
  285. $returnValue = "".$mailsSend." Mails send. ";
  286. if(isset($failedAddresses))
  287. $returnValue .= "\nCould not send to: ".$failedAddresses;
  288. return $returnValue;
  289. }
  290. break;
  291. case "remind":
  292. // XXX:
  293. // TODO:
  294. // if (!isset($_POST['ok']) || !$_POST['ok'])
  295. // {
  296. /*
  297. * look if there were reminders send in the past, and if some tokens got lesser reminders than others
  298. *
  299. * - if so: send reminders to the unremindet participants until they got the same remindcount than the others
  300. * - if not: send reminders normally
  301. */
  302. $remSQL = "SELECT tid, remindercount "
  303. . "FROM ".db_table_name("tokens_{$surveyid}")." "
  304. . "WHERE (completed = 'N' or completed = '') AND sent <> 'N' and sent <>'' AND token <>'' AND EMAIL <>'' "
  305. . "ORDER BY remindercount desc LIMIT 1";
  306. $this->debugLsrc("Executing SQL: ".$remSQL);
  307. $remResult = db_execute_assoc($remSQL);
  308. $remRow = $remResult->FetchRow();
  309. /* Get the reminder count from the row, if we have a row. If
  310. * we don't have a row then we set reminderCount to 0 to prevent
  311. * queries down below from bombing out. */
  312. $reminderCount = $remRow['remindercount'];
  313. if(empty($reminderCount)) {
  314. $this->debugLsrc("There are no reminders to send.");
  315. $reminderCount = 0;
  316. }
  317. $this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", remind ".$remRow['tid']."; ".$reminderCount." ");
  318. $sendOnlySQL = "SELECT tid, remindercount "
  319. . "FROM ".db_table_name("tokens_{$surveyid}")." "
  320. . "WHERE (completed = 'N' or completed = '') AND sent <> 'N' and sent <>'' AND token <>'' AND EMAIL <>'' AND remindercount < ".$reminderCount." "
  321. . "ORDER BY tid asc LIMIT 1";
  322. $this->debugLsrc("Executing SQL: ".$sendOnlySQL);
  323. if($sendOnlyResult->RecordCount()>0)
  324. {
  325. $sendOnlyRow = $sendOnlyResult->FetchRow();
  326. $starttokenid = $sendOnlyRow['tid'];
  327. $this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", remind ".$sendOnlyRow['tid']."; ".$sendOnlyRow['remindercount']." ");
  328. }
  329. if(isset($surveyid) && getEmailFormat($surveyid) == 'html')
  330. {
  331. $ishtml=true;
  332. }
  333. else
  334. {
  335. $ishtml=false;
  336. }
  337. //GET SURVEY DETAILS
  338. $thissurvey=getSurveyInfo($surveyid);
  339. $this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", $surveyid, $type");
  340. // Texte für Mails aus der Datenbank holen.
  341. $sql = "SELECT surveyls_language, surveyls_email_remind_subj, surveyls_email_remind ".
  342. "FROM {$dbprefix}surveys_languagesettings ".
  343. "WHERE surveyls_survey_id = ".$surveyid." ";
  344. $this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", invite ");
  345. $sqlResult = db_execute_assoc($sql);
  346. while($languageRow = $sqlResult->FetchRow())
  347. {
  348. $_POST['message_'.$languageRow['surveyls_language']] = $languageRow['surveyls_email_remind'];
  349. $_POST['subject_'.$languageRow['surveyls_language']] = $languageRow['surveyls_email_remind_subj'];
  350. }
  351. //$tokenoutput .= ("Sending Reminders")."\n";
  352. $surveylangs = GetAdditionalLanguagesFromSurveyID($surveyid);
  353. $baselanguage = GetBaseLanguageFromSurveyID($surveyid);
  354. array_unshift($surveylangs,$baselanguage);
  355. foreach ($surveylangs as $language)
  356. {
  357. $_POST['message_'.$language]=auto_unescape($_POST['message_'.$language]);
  358. $_POST['subject_'.$language]=auto_unescape($_POST['subject_'.$language]);
  359. }
  360. $SQLemailstatuscondition = " AND emailstatus = 'OK'";
  361. if (isset($_POST['maxremindercount']) &&
  362. $_POST['maxremindercount'] != '' &&
  363. intval($_POST['maxremindercount']) != 0)
  364. {
  365. $SQLremindercountcondition = " AND remindercount < ".intval($_POST['maxremindercount']);
  366. }
  367. else
  368. {
  369. $SQLremindercountcondition = "";
  370. }
  371. if (isset($_POST['minreminderdelay']) &&
  372. $_POST['minreminderdelay'] != '' &&
  373. intval($_POST['minreminderdelay']) != 0)
  374. {
  375. // $_POST['minreminderdelay'] in days (86400 seconds per day)
  376. $compareddate = date_shift(date("Y-m-d H:i:s",time() - 86400 * intval($_POST['minreminderdelay'])),
  377. "Y-m-d H:i",$timeadjust);
  378. $SQLreminderdelaycondition = " AND ( "
  379. . " (remindersent = 'N' AND sent < '".$compareddate."') "
  380. . " OR "
  381. . " (remindersent < '".$compareddate."'))";
  382. }
  383. else
  384. {
  385. $SQLreminderdelaycondition = "";
  386. }
  387. $ctquery = "SELECT * FROM ".db_table_name("tokens_{$surveyid}")." WHERE (completed ='N' or completed ='') AND sent<>'' AND sent<>'N' AND token <>'' AND email <> '' $SQLemailstatuscondition $SQLremindercountcondition $SQLreminderdelaycondition";
  388. if (isset($starttokenid)) {$ctquery .= " AND tid >= '{$starttokenid}'";}
  389. // if (isset($tokenid) && $tokenid) {$ctquery .= " AND tid = '{$tokenid}'";}
  390. // //$tokenoutput .= "<!-- ctquery: $ctquery -->\n";
  391. $ctresult = $connect->Execute($ctquery) or $this->debugLsrc ("Database error!\n" . $connect->ErrorMsg());
  392. $ctcount = $ctresult->RecordCount();
  393. $ctfieldcount = $ctresult->FieldCount();
  394. $emquery = "SELECT * ";
  395. //if ($ctfieldcount > 7) {$emquery .= ", attribute_1, attribute_2";}
  396. // TLR change to put date into sent
  397. $emquery .= " FROM ".db_table_name("tokens_{$surveyid}")." WHERE (completed = 'N' or completed = '') AND sent <> 'N' and sent <>'' AND token <>'' AND EMAIL <>'' $SQLemailstatuscondition $SQLremindercountcondition $SQLreminderdelaycondition";
  398. if (isset($starttokenid)) {$emquery .= " AND tid >= '{$starttokenid}'";}
  399. if (isset($tokenid) && $tokenid) {$emquery .= " AND tid = '{$tokenid}'";}
  400. $emquery .= " ORDER BY tid ";
  401. $emresult = db_select_limit_assoc($emquery, $maxemails);
  402. //$emresult = db_execute_assoc($emquery);
  403. $emcount = $emresult->RecordCount();
  404. if ($emcount > 0)
  405. {
  406. while ($emrow = $emresult->FetchRow())
  407. {
  408. $c=1;
  409. unset($fieldsarray);
  410. $to = $emrow['email'];
  411. $fieldsarray["{EMAIL}"]=$emrow['email'];
  412. $fieldsarray["{FIRSTNAME}"]=$emrow['firstname'];
  413. $fieldsarray["{LASTNAME}"]=$emrow['lastname'];
  414. $fieldsarray["{TOKEN}"]=$emrow['token'];
  415. $fieldsarray["{LANGUAGE}"]=$emrow['language'];
  416. while(isset($emrow["attribute_$c"]))
  417. {
  418. $fieldsarray["{ATTRIBUTE_$c}"]=$emrow["attribute_$c"];
  419. ++$c;
  420. }
  421. $fieldsarray["{ADMINNAME}"]= $thissurvey['adminname'];
  422. $fieldsarray["{ADMINEMAIL}"]=$thissurvey['adminemail'];
  423. $fieldsarray["{SURVEYNAME}"]=$thissurvey['name'];
  424. $fieldsarray["{SURVEYDESCRIPTION}"]=$thissurvey['description'];
  425. $fieldsarray["{EXPIRY}"]=$thissurvey["expiry"];
  426. $emrow['language']=trim($emrow['language']);
  427. if ($emrow['language']=='') {$emrow['language']=$baselanguage;} //if language is not give use default
  428. if(!in_array($emrow['language'], $surveylangs)) {$emrow['language']=$baselanguage;} // if given language is not available use default
  429. $found = array_search($emrow['language'], $surveylangs);
  430. if ($found==false) {$emrow['language']=$baselanguage;}
  431. $from = $thissurvey['adminemail'];
  432. if (getEmailFormat($surveyid) == 'html')
  433. {
  434. $ishtml=true;
  435. }
  436. else
  437. {
  438. $ishtml=false;
  439. }
  440. if ($ishtml == false)
  441. {
  442. if ( $modrewrite )
  443. {
  444. $fieldsarray["{SURVEYURL}"]="$publicurl/$surveyid/lang-".trim($emrow['language'])."/tk-{$emrow['token']}";
  445. }
  446. else
  447. {
  448. $fieldsarray["{SURVEYURL}"]="$publicurl/index.php?lang=".trim($emrow['language'])."&sid=$surveyid&token={$emrow['token']}";
  449. }
  450. }
  451. else
  452. {
  453. if ( $modrewrite )
  454. {
  455. $fieldsarray["{SURVEYURL}"]="<a href='$publicurl/$surveyid/lang-".trim($emrow['language'])."/tk-{$emrow['token']}'>".htmlspecialchars("$publicurl/$surveyid/lang-".trim($emrow['language'])."/tk-{$emrow['token']}")."</a>";
  456. }
  457. else
  458. {
  459. $fieldsarray["{SURVEYURL}"]="<a href='$publicurl/index.php?lang=".trim($emrow['language'])."&sid=$surveyid&token={$emrow['token']}'>".htmlspecialchars("$publicurl/index.php?lang=".trim($emrow['language'])."&sid=$surveyid&token={$emrow['token']}")."</a>";
  460. $_POST['message_'.$emrow['language']] = html_entity_decode($_POST['message_'.$emrow['language']], ENT_QUOTES, $emailcharset);
  461. }
  462. }
  463. $msgsubject=Replacefields($_POST['subject_'.$emrow['language']], $fieldsarray);
  464. $sendmessage=Replacefields($_POST['message_'.$emrow['language']], $fieldsarray);
  465. if (SendEmailMessage($sendmessage, $msgsubject, $to, $from, $sitename, $ishtml, getBounceEmail($surveyid)))
  466. {
  467. // Put date into remindersent
  468. $today = date("Y-m-d H:i");
  469. $udequery = "UPDATE ".db_table_name("tokens_{$surveyid}")."\n"
  470. ."SET remindersent='$today',remindercount = remindercount+1 WHERE tid={$emrow['tid']}";
  471. //
  472. $uderesult = $connect->Execute($udequery) or $this->debugLsrc ("Could not update tokens$udequery".$connect->ErrorMsg());
  473. //orig: $tokenoutput .= "\t\t\t({$emrow['tid']})[".("Reminder sent to:")." {$emrow['firstname']} {$emrow['lastname']}]\n";
  474. //$tokenoutput .= "\t\t\t({$emrow['tid']}) [".("Reminder sent to:")." {$emrow['firstname']} {$emrow['lastname']} ($to)]\n";
  475. $mailsSend++;
  476. }
  477. else
  478. {
  479. //$tokenoutput .= ReplaceFields(("Email to {FIRSTNAME} {LASTNAME} ({EMAIL}) failed. Error Message:")." ".$maildebug."", $fieldsarray);
  480. if($n==1)
  481. $failedAddresses .= ",".$to;
  482. else
  483. {
  484. $failedAddresses = $to;
  485. $n=1;
  486. }
  487. }
  488. //$lasttid = $emrow['tid'];
  489. }
  490. if ($ctcount > $emcount)
  491. {
  492. $lefttosend = $ctcount-$maxemails;
  493. }else{$lefttosend = 0;}
  494. }
  495. else
  496. {
  497. return "No Reminders to send";
  498. }
  499. if($maxemails>0)
  500. {
  501. $returnValue = "".$mailsSend." Reminders send. ".$lefttosend." Reminders left to send";
  502. if(isset($failedAddresses))
  503. $returnValue .= "\nCould not send to: ".$failedAddresses;
  504. return $returnValue;
  505. }
  506. if(isset($mailsSend))
  507. {
  508. $returnValue = "".$mailsSend." Reminders send. ";
  509. if(isset($failedAddresses))
  510. $returnValue .= "\nCould not send to: ".$failedAddresses;
  511. return $returnValue;
  512. }
  513. break;
  514. default:
  515. break;
  516. }
  517. }
  518. /**
  519. * loginCheck for Lsrc, checks if the user with given password exists in LS Database and
  520. * sets the SESSION rights for this user
  521. * @param String $sUser
  522. * @param String $sPass
  523. * @return boolean
  524. */
  525. function checkUser($sUser, $sPass) // XXX
  526. {
  527. global $connect ;
  528. global $dbprefix ;
  529. $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
  530. include("lsrc.config.php");
  531. require(dirname(__FILE__)."/../classes/core/sha256.php");
  532. $query="SELECT uid, password, lang, superadmin FROM {$dbprefix}users WHERE users_name=".$connect->qstr(sanitize_user($sUser));
  533. // echo $query;
  534. $result = db_execute_assoc($query);
  535. $gv = $result->FetchRow();
  536. if($result->RecordCount() < 1)
  537. {
  538. return false;
  539. }
  540. else
  541. {
  542. if((SHA256::hashing($sPass)==$gv['password']))
  543. {
  544. $_SESSION['loginID']=$gv['uid'];
  545. $_SESSION['lang']=$gv['lang'];
  546. $squery = "SELECT create_survey, configurator, create_user, delete_user, superadmin, manage_template, manage_label FROM {$dbprefix}users WHERE uid={$gv['uid']}";
  547. $sresult = db_execute_assoc($squery); //Checked
  548. if ($sresult->RecordCount()>0)
  549. {
  550. $fields = $sresult->FetchRow();
  551. $_SESSION['USER_RIGHT_CREATE_SURVEY'] = $fields['create_survey'];
  552. $_SESSION['USER_RIGHT_CONFIGURATOR'] = $fields['configurator'];
  553. $_SESSION['USER_RIGHT_CREATE_USER'] = $fields['create_user'];
  554. $_SESSION['USER_RIGHT_DELETE_USER'] = $fields['delete_user'];
  555. $_SESSION['USER_RIGHT_SUPERADMIN'] = $fields['superadmin'];
  556. $_SESSION['USER_RIGHT_MANAGE_TEMPLATE'] = $fields['manage_template'];
  557. $_SESSION['USER_RIGHT_MANAGE_LABEL'] = $fields['manage_label'];
  558. }
  559. return true;
  560. }
  561. else
  562. {
  563. return false;
  564. }
  565. }
  566. }
  567. /**
  568. * Lsrc checks the existence of Surveys more than one time, so this makes sense to be DRY
  569. *
  570. * @param int $sid
  571. * @return boolean
  572. */
  573. function surveyExists($sid)//XXX
  574. {
  575. global $connect ;
  576. global $dbprefix ;
  577. $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
  578. include("lsrc.config.php");
  579. $query="SELECT * FROM {$dbprefix}surveys WHERE sid = ".$sid;
  580. // echo $query;
  581. $result = db_execute_assoc($query);
  582. if($result->RecordCount() < 1)
  583. {
  584. return false;
  585. }
  586. else
  587. {
  588. return true;
  589. }
  590. }
  591. /**
  592. * function to import surveys
  593. *
  594. * @param $iVid - desired survey id
  595. * @param $importFile - name of the file to import in core(survey) dir
  596. * @return boolean
  597. */
  598. function importSurvey($iVid, $importFile)
  599. {
  600. global $connect ;
  601. global $dbprefix ;
  602. global $clang;
  603. include("lsrc.config.php");
  604. $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
  605. $this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", OK ");
  606. // HINT FOR IMPORTERS: go to Line 714 to manipulate the Survey, while it's imported
  607. $the_full_file_path = $coreDir.$importFile;
  608. $this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.",the_full_file_path ='$the_full_file_path' OK ");
  609. include("../import_functions.php");
  610. include("../admin_functions.php");
  611. if (!isset($copyfunction))
  612. {
  613. $sFullFilepath=$the_full_file_path;
  614. $aPathInfo = pathinfo($sFullFilepath);
  615. $sExtension = $aPathInfo['extension'];
  616. }
  617. if (isset($sExtension) && strtolower($sExtension)=='csv')
  618. {
  619. $aImportResults=CSVImportSurvey($sFullFilepath,$iVid);
  620. }
  621. elseif (isset($sExtension) && strtolower($sExtension)=='lss')
  622. {
  623. $aImportResults=XMLImportSurvey($sFullFilepath,NULL,NULL,$iVid);
  624. } elseif (isset($copyfunction))
  625. {
  626. $aImportResults=XMLImportSurvey('',$copysurveydata,$sNewSurveyName,$iVid);
  627. }
  628. //CANNOT BE USED BY LSRC RIGHT NOW
  629. // Translate INSERTANS codes if chosen
  630. // if (isset($aImportResults['fieldnames']) && $sTransLinks === true)
  631. // {
  632. // transInsertAns($aImportResults['newsid'],$aImportResults['oldsid'],$aImportResults['fieldnames']);
  633. // }
  634. return $aImportResults['newsid'];
  635. }
  636. /**
  637. * function to activate surveys based on new activate.php 5771 2008-10-13 02:28:40Z jcleeland $
  638. *
  639. * @param unknown_type $surveyid
  640. * @return boolean
  641. */
  642. function activateSurvey($surveyid)//XXX activateSurvey
  643. {
  644. global $dbprefix, $connect, $clang, $databasetype,$databasetabletype;
  645. $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
  646. include("lsrc.config.php");
  647. include('../admin_functions.php');
  648. include('../activate_functions.php');
  649. $this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", OK ");
  650. $returnOutput = activateSurvey($surveyid,$surveyid,'lsrc');
  651. $this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", $returnOutput ");
  652. return $returnOutput;
  653. } // end activateSurvey();
  654. /**
  655. * not used, a test, thought this could maybe enhance security, may be deleted
  656. *
  657. * @return Error 404 fake
  658. */
  659. function fake404()// XXX
  660. {
  661. return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  662. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  663. <html xmlns="http://www.w3.org/1999/xhtml" lang="de" xml:lang="de">
  664. <head>
  665. <title>Objekt nicht gefunden!</title>
  666. <link rev="made" href="" />
  667. <style type="text/css"><!--/*--><![CDATA[/*><!--*/
  668. body { color: #000000; background-color: #FFFFFF; }
  669. a:link { color: #0000CC; }
  670. p, address {margin-left: 3em;}
  671. span {font-size: smaller;}
  672. /*]]>*/--></style>
  673. </head>
  674. <body>
  675. <h1>Objekt nicht gefunden!</h1>
  676. <p>
  677. Der angeforderte URL konnte auf dem Server nicht gefunden werden.
  678. Sofern Sie den URL manuell eingegeben haben,
  679. &uuml;berpr&uuml;fen Sie bitte die Schreibweise und versuchen Sie es erneut.
  680. </p>
  681. <p>
  682. Sofern Sie dies f&uuml;r eine Fehlfunktion des Servers halten,
  683. informieren Sie bitte den
  684. <a href="mailto:webmaster@'.$_SERVER["SERVER_NAME"].'">Webmaster</a>
  685. hier&uuml;ber.
  686. </p>
  687. <h2>Error 404</h2>
  688. <address>
  689. <a href="/">'.$_SERVER["SERVER_NAME"].'</a>
  690. <span>'.date("m/d/Y H:i:s").'
  691. Apache/2.2.9 (Win32) DAV/2 mod_ssl/2.2.9 OpenSSL/0.9.8i mod_autoindex_color PHP/5.2.6 mod_jk/1.2.26</span>
  692. </address>
  693. </body>
  694. </html>
  695. ';
  696. }
  697. /**
  698. * importing a group into an existing survey
  699. *
  700. * @param int $iVid SurveyID
  701. * @param string $sMod Group that should be loaded into the Survey
  702. */
  703. function importGroup($surveyid, $sMod) //XXX
  704. {
  705. global $connect ;
  706. global $dbprefix ;
  707. $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
  708. include("lsrc.config.php");
  709. $newsid = $surveyid;
  710. $this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", OK ");
  711. $the_full_file_path = $modDir.$sMod.".csv";
  712. $this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", OK $the_full_file_path ");
  713. $handle = fopen($the_full_file_path, "r");
  714. while (!feof($handle))
  715. {
  716. $buffer = fgets($handle);
  717. $bigarray[] = $buffer;
  718. }
  719. fclose($handle);
  720. if (substr($bigarray[0], 0, 23) != "# LimeSurvey Group Dump" && substr($bigarray[0], 0, 24) != "# PHPSurveyor Group Dump")
  721. {
  722. //$importgroup .= "<strong><font color='red'>".("Error")."</font></strong>\n";
  723. //$importgroup .= ("This file is not a LimeSurvey group file. Import failed.")."\n";
  724. //$importgroup .= "<input type='submit' value='".("Main Admin Screen")."' onclick=\"window.open('$scriptname', '_top')\">\n";
  725. //$importgroup .= "</td></tr></table>\n";
  726. //unlink($the_full_file_path);
  727. return false;
  728. }
  729. for ($i=0; $i<9; $i++)
  730. {
  731. unset($bigarray[$i]);
  732. }
  733. $bigarray = array_values($bigarray);
  734. //GROUPS
  735. if (array_search("# QUESTIONS TABLE\n", $bigarray))
  736. {
  737. $stoppoint = array_search("# QUESTIONS TABLE\n", $bigarray);
  738. }
  739. elseif (array_search("# QUESTIONS TABLE\r\n", $bigarray))
  740. {
  741. $stoppoint = array_search("# QUESTIONS TABLE\r\n", $bigarray);
  742. }
  743. else
  744. {
  745. $stoppoint = count($bigarray)-1;
  746. }
  747. for ($i=0; $i<=$stoppoint+1; $i++)
  748. {
  749. if ($i<$stoppoint-2) {$grouparray[] = $bigarray[$i];}
  750. unset($bigarray[$i]);
  751. }
  752. $bigarray = array_values($bigarray);
  753. $this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", OK ");
  754. //QUESTIONS
  755. if (array_search("# ANSWERS TABLE\n", $bigarray))
  756. {
  757. $stoppoint = array_search("# ANSWERS TABLE\n", $bigarray);
  758. }
  759. elseif (array_search("# ANSWERS TABLE\r\n", $bigarray))
  760. {
  761. $stoppoint = array_search("# ANSWERS TABLE\r\n", $bigarray);
  762. }
  763. else
  764. {
  765. $stoppoint = count($bigarray)-1;
  766. }
  767. for ($i=0; $i<=$stoppoint+1; $i++)
  768. {
  769. if ($i<$stoppoint-2) {$questionarray[] = $bigarray[$i];}
  770. unset($bigarray[$i]);
  771. }
  772. $bigarray = array_values($bigarray);
  773. $this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", OK ");
  774. //ANSWERS
  775. if (array_search("# CONDITIONS TABLE\n", $bigarray))
  776. {
  777. $stoppoint = array_search("# CONDITIONS TABLE\n", $bigarray);
  778. }
  779. elseif (array_search("# CONDITIONS TABLE\r\n", $bigarray))
  780. {
  781. $stoppoint = array_search("# CONDITIONS TABLE\r\n", $bigarray);
  782. }
  783. else
  784. {
  785. $stoppoint = count($bigarray)-1;
  786. }
  787. for ($i=0; $i<=$stoppoint+1; $i++)
  788. {
  789. if ($i<$stoppoint-2) {$answerarray[] = $bigarray[$i];}
  790. unset($bigarray[$i]);
  791. }
  792. $bigarray = array_values($bigarray);
  793. $this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", OK ");
  794. //CONDITIONS
  795. if (array_search("# LABELSETS TABLE\n", $bigarray))
  796. {
  797. $stoppoint = array_search("# LABELSETS TABLE\n", $bigarray);
  798. }
  799. elseif (array_search("# LABELSETS TABLE\r\n", $bigarray))
  800. {
  801. $stoppoint = array_search("# LABELSETS TABLE\r\n", $bigarray);
  802. }
  803. else
  804. {
  805. $stoppoint = count($bigarray);
  806. }
  807. for ($i=0; $i<=$stoppoint+1; $i++)
  808. {
  809. if ($i<$stoppoint-2) {$conditionsarray[] = $bigarray[$i];}
  810. unset($bigarray[$i]);
  811. }
  812. $bigarray = array_values($bigarray);
  813. $this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", OK ");
  814. //LABELSETS
  815. if (array_search("# LABELS TABLE\n", $bigarray))
  816. {
  817. $stoppoint = array_search("# LABELS TABLE\n", $bigarray);
  818. }
  819. elseif (array_search("# LABELS TABLE\r\n", $bigarray))
  820. {
  821. $stoppoint = array_search("# LABELS TABLE\r\n", $bigarray);
  822. }
  823. else
  824. {
  825. $stoppoint = count($bigarray)-1;
  826. }
  827. for ($i=0; $i<=$stoppoint+1; $i++)
  828. {
  829. if ($i<$stoppoint-2) {$labelsetsarray[] = $bigarray[$i];}
  830. unset($bigarray[$i]);
  831. }
  832. $bigarray = array_values($bigarray);
  833. $this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", OK ");
  834. //LABELS
  835. if (array_search("# QUESTION_ATTRIBUTES TABLE\n", $bigarray))
  836. {
  837. $stoppoint = array_search("# QUESTION_ATTRIBUTES TABLE\n", $bigarray);
  838. }
  839. elseif (array_search("# QUESTION_ATTRIBUTES TABLE\r\n", $bigarray))
  840. {
  841. $stoppoint = array_search("# QUESTION_ATTRIBUTES TABLE\r\n", $bigarray);
  842. }
  843. else
  844. {
  845. $stoppoint = count($bigarray)-1;
  846. }
  847. for ($i=0; $i<=$stoppoint+1; $i++)
  848. {
  849. if ($i<$stoppoint-2) {$labelsarray[] = $bigarray[$i];}
  850. unset($bigarray[$i]);
  851. }
  852. $bigarray = array_values($bigarray);
  853. $this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", OK ");
  854. //LAST LOT (now question_attributes)
  855. if (!isset($noconditions) || $noconditions != "Y")
  856. {
  857. // stoppoint is the last line number
  858. // this is an empty line after the QA CSV lines
  859. $stoppoint = count($bigarray)-1;
  860. for ($i=0; $i<=$stoppoint+1; $i++)
  861. {
  862. if ($i<=$stoppoint-1) {$question_attributesarray[] = $bigarray[$i];}
  863. unset($bigarray[$i]);
  864. }
  865. }
  866. $bigarray = array_values($bigarray);
  867. $countgroups=0;
  868. if (isset($questionarray))
  869. {
  870. $questionfieldnames=convertCSVRowToArray($questionarray[0],',','"');
  871. unset($questionarray[0]);
  872. $countquestions = 0;
  873. }
  874. if (isset($answerarray))
  875. {
  876. $answerfieldnames=convertCSVRowToArray($answerarray[0],',','"');
  877. unset($answerarray[0]);
  878. $countanswers = 0;
  879. }
  880. $countconditions = 0;
  881. $countlabelsets=0;
  882. $countlabels=0;
  883. $countquestion_attributes = 0;
  884. $countanswers = 0;
  885. $this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", OK ");
  886. // first check that imported group, questions and labels support the
  887. // current survey's baselang
  888. $langcode = GetBaseLanguageFromSurveyID($newsid);
  889. if (isset($grouparray))
  890. {
  891. $groupfieldnames = convertCSVRowToArray($grouparray[0],',','"');
  892. $langfieldnum = array_search("language", $groupfieldnames);
  893. $gidfieldnum = array_search("gid", $groupfieldnames);
  894. $groupssupportbaselang = bDoesImportarraySupportsLanguage($grouparray,Array($gidfieldnum),$langfieldnum,$langcode,true);
  895. if (!$groupssupportbaselang)
  896. {
  897. //$importgroup .= "<strong><font color='red'>".("Error")."</font></strong>\n";
  898. //$importgroup .= ("You can't import a group which doesn't support the current survey's base language.")."\n";
  899. //$importgroup .= "<input type='submit' value='".("Main Admin Screen")."' onclick=\"window.open('$scriptname', '_top')\">\n";
  900. //$importgroup .= "</td></tr></table>\n";
  901. //unlink($the_full_file_path);
  902. return "Group does not support Surveys Baselanguage ($langcode)";
  903. }
  904. }
  905. $this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", OK ");
  906. if (isset($questionarray))
  907. {
  908. $langfieldnum = array_search("language", $questionfieldnames);
  909. $qidfieldnum = array_search("qid", $questionfieldnames);
  910. $questionssupportbaselang = bDoesImportarraySupportsLanguage($questionarray,Array($qidfieldnum), $langfieldnum,$langcode,false);
  911. if (!$questionssupportbaselang)
  912. {
  913. //$importgroup .= "<strong><font color='red'>".("Error")."</font></strong>\n";
  914. //$importgroup .= ("You can't import a question which doesn't support the current survey's base language.")."\n";
  915. //$importgroup .= "<input type='submit' value='".("Main Admin Screen")."' onclick=\"window.open('$scriptname', '_top')\">\n";
  916. //$importgroup .= "</td></tr></table>\n";
  917. //unlink($the_full_file_path);
  918. return "Group does not support Surveys Baselanguage ($langcode)";
  919. }
  920. }
  921. $this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", OK ");
  922. if (isset($labelsetsarray))
  923. {
  924. $labelsetfieldname = convertCSVRowToArray($labelsetsarray[0],',','"');
  925. $langfieldnum = array_search("languages", $labelsetfieldname);
  926. $lidfilednum = array_search("lid", $labelsetfieldname);
  927. $labelsetssupportbaselang = bDoesImportarraySupportsLanguage($labelsetsarray,Array($lidfilednum),$langfieldnum,$langcode,true);
  928. if (!$labelsetssupportbaselang)
  929. {
  930. $importquestion .= "<strong><font color='red'>".("Error")."</font></strong>\n"
  931. .("You can't import label sets which don't support the current survey's base language")."\n"
  932. ."</td></tr></table>\n";
  933. //unlink($the_full_file_path);
  934. return "Group does not support Surveys Baselanguage ($langcode)";
  935. }
  936. }
  937. $newlids = array(); // this array will have the "new lid" for the label sets, the key will be the "old lid"
  938. $this->debugLsrc("wir sind in ".__FILE__." - ".__FUNCTION__." Line ".__LINE__.", OK ");
  939. //DO ANY LABELSETS FIRST, SO WE CAN KNOW WHAT THEIR NEW LID IS FOR THE QUESTIONS
  940. if (isset($labelsetsarray) && $labelsetsarray) {
  941. $csarray=buildLabelSetCheckSumArray(); // build checksums over all existing labelsets
  942. $count=0;
  943. foreach ($labelsetsarray as $lsa) {
  944. $fieldorders =convertCSVRowToArray($labelsetsarray[0],',','"');
  945. $fieldcontents=convertCSVRowToArray($lsa,',','"');
  946. if ($count==0) {$count++; continue;}
  947. $countlabelsets++;
  948. $labelsetrowdata=array_combine($fieldorders,$fieldcontents);
  949. // Save old labelid
  950. $oldlid=$labelsetrowdata['lid'];
  951. // set the new language
  952. unset($labelsetrowdata['lid']);
  953. $newvalues=array_values($labelsetrowdata);
  954. $newvalues=array_map(array(&$connect, "qstr"),$newvalues); // quote everything accordingly
  955. $lsainsert = "INSERT INTO {$dbprefix}labelsets (".implode(',',array_keys($labelsetrowdata)).") VALUES (".implode(',',$newvalues).")"; //handle db prefix
  956. $lsiresult=$connect->Execute($lsainsert);
  957. // Get the new insert id for the labels inside this labelset
  958. $newlid=$connect->Insert_ID("{$dbprefix}labelsets",'lid');
  959. if ($labelsarray) {
  960. $count=0;
  961. foreach ($labelsarray as $la) {
  962. $lfieldorders =convertCSVRowToArray($labelsarray[0],',','"');
  963. $lfieldcontents=convertCSVRowToArray($la,',','"');
  964. if ($count==0) {$count++; continue;}
  965. // Combine into one array with keys and values since its easier to handle
  966. $labelrowdata=array_combine($lfieldorders,$lfieldcontents);
  967. $labellid=$labelrowdata['lid'];
  968. if ($labellid == $oldlid) {
  969. $labelrowdata['lid']=$newlid;
  970. // translate internal links
  971. $labelrowdata['title']=translink('label', $oldlid, $newlid, $labelrowdata['title']);
  972. $newvalues=array_values($labelrowdata);
  973. $newvalues=array_map(array(&$connect, "qstr"),$newvalues); // quote everything accordingly
  974. $lainsert = "INSERT INTO {$dbprefix}labels (".implode(',',array_keys($labelrowdata)).") VALUES (".implode(',',$newvalues).")"; //handle db prefix
  975. $liresult=$connect->Execute($lainsert);
  976. $countlabels++;
  977. }
  978. }
  979. }
  980. //CHECK FOR DUPLICATE LABELSETS
  981. $thisset="";
  982. $query2 = "SELECT code, title, sortorder, language
  983. FROM {$dbprefix}labels
  984. WHERE lid=".$newlid."
  985. ORDER BY language, sortorder, code";
  986. $result2 = db_execute_num($query2) or $this->debugLsrc("Died querying labelset $lid$query2".$connect->ErrorMsg());
  987. while($row2=$result2->FetchRow())
  988. {
  989. $thisset .= implod

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