Posted By

olesla on 08/05/15


Tagged

js php


Versions (?)

userlists


 / Published in: JavaScript
 

URL: _m3

dynamisk listegenerering

  1. <?php
  2. /*
  3. Todo:
  4. Forhindre at brukere skriver html i input felter
  5. Lime inn r���¥data / Importer ny fil fra eksisterende excel fil.
  6. Sortere etter navn/dato/status/privat.
  7. Fullskjerm.
  8. Kolonnenavn kan ikke inneholde speialtegn, da f���¥r man ikke satt inn nye rader eller endret eksisterende
  9. Tooltips.
  10. */
  11. $listDB = "prosjekt.userlists";
  12. $listDataDBN = "userlist_management.list_";
  13. if($_SERVER['REQUEST_METHOD'] == 'POST')
  14. {
  15. header("Content-Type: text/html; charset=utf-8");
  16. session_start();
  17. require_once("/var/www/maestro/src/tools.php");
  18. require_once("/var/www/maestro/src/functions.php");
  19. $maestro_db = db_connect("m3");
  20. escape_post_vars();
  21. switch($_POST['action'])
  22. {
  23. case "deleteprivaterow":
  24. $id=$_POST['id'];
  25. $rowid=$_POST['rowid'];
  26. $maestro_db->query("DELETE FROM userlist_management.list_{$id} WHERE id='$rowid'");
  27. if ($maestro_db->error != "")
  28. {
  29. $return = $maestro_db->error;
  30. }
  31. else
  32. {
  33. $return = "success";
  34. }
  35. die($return);
  36. break;
  37.  
  38. case "update_specific_header":
  39. $listid = $_POST['rowid'];
  40. $oldname = $_POST['value'];
  41. $newname = $_POST['newname'];
  42. $originalId = $_POST['originalid'];
  43. $newname = strip_tags($newname);
  44. $checkUid=$maestro_db->query("SELECT uid FROM $listDB WHERE id='$originalId'")->fetch_assoc()['uid'];
  45. $return = $originalId;
  46. if($checkUid==$_SESSION['uid'])
  47. {
  48. $maestro_db->query("ALTER TABLE userlist_management.list_{$originalId} CHANGE `$oldname` `$newname` TEXT CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL");
  49. if ($maestro_db->error != "")
  50. $return = $maestro_db->error;
  51. else
  52. $return = "success";
  53. }
  54. else
  55. {
  56. $return="wronguid";
  57. }
  58. die($return);
  59. break;
  60.  
  61. case "update_specific_list":
  62. $listid = $_POST['rowid'];
  63. $newname = $_POST['newname'];
  64. $header = $_POST['header'];
  65. $originalId = $_POST['originalid'];
  66. $newname = strip_tags($newname);
  67. $checkUid=$maestro_db->query("SELECT uid FROM $listDB WHERE id='$originalId'")->fetch_assoc()['uid'];
  68. $return = $originalId;
  69. if($checkUid==$_SESSION['uid'])
  70. {
  71. $maestro_db->query("UPDATE userlist_management.list_{$originalId} SET {$header}='$newname' WHERE id='$listid'");
  72. $checkLastRowResult=$maestro_db->query("SELECT * FROM userlist_management.list_{$originalId} ORDER BY id DESC LIMIT 1"); // ?
  73.  
  74. if ($maestro_db->error != "")
  75. $return = $maestro_db->error;
  76. else
  77. $return = "success";
  78. }
  79. else
  80. {
  81. $return="wronguid";
  82. }
  83. die($return);
  84. break;
  85.  
  86. case "specificlist":
  87. $id=$_POST['id'];
  88. $listname=$maestro_db->query("SELECT * FROM prosjekt.userlists WHERE id='$id'")->fetch_assoc();
  89. if ($listname['uid'] == $_SESSION['uid'])
  90. {
  91. $result=$maestro_db->query("SELECT * FROM userlist_management.list_{$id}");
  92. $return .= "<table class='aleks_table smaller' width=100% border=0>";
  93. $first=true;
  94. $last=true;
  95. $numItems=count($result->fetch_assoc());
  96. foreach($result as $row)
  97. {
  98. if($first)
  99. {
  100. $return .= "<tr class='row-b'>";
  101. foreach($row as $key => $field)
  102. {
  103. if($key=='id' || $key=='reg_date' || $key=='added_by')
  104. continue;
  105.  
  106. $return .= "<td class='row-b'><strong><div class='editheader' style='cursor: pointer'>". $key ."</div></strong></td>";
  107. }
  108. $return .= "<td class='row-b'><strong></strong></td></tr>";
  109. $first = false;
  110. }
  111. $return .= "<tr class='row-a'>";
  112. foreach($row as $key => $field)
  113. {
  114. if($key=='id' || $key=='reg_date' || $key=='added_by')
  115. continue;
  116.  
  117. $return .= "<td class='row-d' height='16'><font color='black'> <div class='editlist' id='{$row['id']}' name='{$key}' style='cursor: pointer'>".(empty($row[$key]) ? "&nbsp;" : $row[$key] )."</div></font></td>";
  118. }
  119. $return .= "<td class='row-d' height='16'><a href='#' onclick='deleteRow({$row['id']}, {$id});'><img src='img/fugue_icons/cross.png' style='float: right;'></a></td></tr>";
  120. }
  121. $return .= "</table>";
  122. $return .= "<br><div class='addRowPrivate' style='cursor: pointer'><center><a href='#' onclick='addRowToList({$id});'>Legg til rad</a></center></div>";
  123. }
  124. else
  125. {
  126. $return="wronguid";
  127. }
  128. die($return);
  129. break;
  130.  
  131. case "deletelist":
  132. $listid=$_POST['id'];
  133. $checkUid=$maestro_db->query("SELECT uid FROM $listDB WHERE id='$listid'")->fetch_assoc()['uid'];
  134. if($checkUid == $_SESSION['uid'])
  135. {
  136. $maestro_db->query("UPDATE $listDB SET deleted='1' WHERE id='$listid'");
  137.  
  138. if ($maestro_db->error != "")
  139. $return = $maestro_db->error;
  140. else
  141. $return = "success";
  142. }
  143. else
  144. {
  145. $return = "wronguid";
  146. }
  147.  
  148. die($return);
  149. break;
  150.  
  151. case "savelist":
  152. $columns=clean($_POST['columns']);
  153. $private=$_POST['private'];
  154. $listname="New List " . date('Y-m-d H:i:s');
  155. $sql="INSERT INTO $listDB (uid,state,list_name,private) VALUES ('{$_SESSION['uid']}','open','$listname', $private)";
  156.  
  157. if($maestro_db->query($sql) === TRUE)
  158. {
  159. $last_id = $maestro_db->insert_id;
  160. }
  161. else
  162. {
  163. $return=$maestro_db->error;
  164. die($return);
  165. }
  166. $columnsSql="CREATE TABLE userlist_management.list_".$maestro_db->real_escape_string($last_id)."(id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,\r\n";
  167. foreach($columns as $col)
  168. {
  169.  
  170. $columnsSql .= "`" . clean($col) . "` " . "text NOT NULL,\r\n";
  171. }
  172. $columnsSql .= "reg_date TIMESTAMP,\r\n
  173. added_by text NOT NULL)";
  174. $maestro_db->query($columnsSql);
  175.  
  176. if ($maestro_db->error != "")
  177. {
  178. $return = $maestro_db->error;
  179. $maestro_db->query("DELETE FROM $listDB WHERE id=$last_id");
  180. }
  181. else
  182. {
  183. $return = "success";
  184. }
  185. die($return);
  186. break;
  187.  
  188. case "make_new_list":
  189. $return='<table class="aleks_table smaller" id="newlist" width=100% border=0>
  190. <tbody>
  191. <tr class="row-a"><td><font color="black"><div class="columnname" style="cursor: pointer">Kolonnenavn</div></font></td></tr>
  192. </tbody>
  193. <tr class="row-b" id="addcolumn"><td><strong><a href="#" onclick="addcolumn();">Legg til kolonne</a></strong></td></tr>
  194. <tr class="row-b" id="listoptions"><td><input type="checkbox" id="private" name="private" value="private"><font color="black">Gj���¸r listen min privat</font><input type="submit" class="fancypants_button fancy_green" value="Lagre" onclick="savelist();" style="float: right;"></td></tr>
  195. </table>';
  196. die($return);
  197. break;
  198.  
  199. case "change_list_name":
  200. $listid = $_POST['listid'];
  201. $newname = $_POST['newname'];
  202. $newname = strip_tags($newname);
  203. $checkUid=$maestro_db->query("SELECT uid FROM $listDB WHERE id='$listid'")->fetch_assoc()['uid'];
  204. if($checkUid==$_SESSION['uid'])
  205. {
  206. if(!empty($newname))
  207. {
  208. $maestro_db->query("UPDATE $listDB SET list_name='$newname' WHERE id='$listid'");
  209.  
  210. if ($maestro_db->error != "")
  211. $return = $maestro_db->error;
  212. else
  213. $return = "success";
  214. }
  215. else
  216. {
  217. $return = "invalid";
  218. }
  219. }
  220. else
  221. {
  222. $return = "wronguid";
  223. }
  224. die($return);
  225. break;
  226.  
  227. case "getlist":
  228. $fetchList=$maestro_db->query("SELECT * FROM $listDB WHERE uid={$_SESSION['uid']} AND deleted=0 ORDER BY id DESC");
  229. $return = '<table class="aleks_table smaller" width=100% border=0>
  230. <tr class="row-b">
  231. <td class="row-b"></td>
  232. <td class="row-b"><strong>Navn</td>
  233. <td class="row-b"><strong>Dato</strong></td>
  234. <td class="row-b"><strong>L���¥s</strong></td>
  235. <td class="row-b"><strong>Privat</strong></td>
  236. <td class="row-b"><strong>Delt med</strong></td>
  237. </tr>';
  238. while($r=$fetchList->fetch_assoc())
  239. {
  240. if($r['uid']==$_SESSION['uid'])
  241. {
  242. $listname=$r['list_name'];
  243. $return .= "<tr class='row-c'>
  244. <td nowrap><a href='#' onclick='specificlist({$r['id']});'><img src='/_m3/img/16x16/flip_down.png' height='16' width='16'></a> <div id='downloadcsv' style='display:inline;'><a href='#' onclick='downloadCsvList({$r['id']});'><img src='img/file_icons/excel.png'></a></div> <a href='#' onclick='deletelist({$r['id']});'><img src='img/fugue_icons/cross.png' height='16' width='16'></a></td>
  245. <td nowrap><font color='black'><div class='listname' id='{$r['id']}' style='cursor: pointer'>$listname</div></font></td>
  246. <td nowrap><font color='black'>{$r['date']}</font></td>
  247. <td nowrap>".($r['state'] == "open" ? "<a href='#' onclick='changeOpen({$r['id']});'><img src='img/switches/off.png' width='50' height='15'/></a>" : "<a href='#' onclick='changeOpen({$r['id']});'><img src='img/switches/on.png' width='50' height='15'/></a>")."</td>
  248. <td nowrap>".($r['private'] == 0 ? "<a href='#' onclick='changePrivate({$r['id']});'><img src='img/switches/off.png' width='50' height='15'/></a>" : "<a href='#' onclick='changePrivate({$r['id']});'><img src='img/switches/on.png' width='50' height='15'/></a></center>")."</td>
  249. <td nowrap>".($r['private'] == 1 ? "<a href='#' onclick=\"popup('popUpDiv', {$r['id']})\">Vis/Endre</a>" : "")."</td>
  250. </tr>";
  251. }
  252. }
  253. $return.="</table>";
  254. die($return);
  255. break;
  256.  
  257. case "getsharedlists":
  258. $fetchList=$maestro_db->query("SELECT * FROM $listDB WHERE private=0 AND deleted=0 ORDER BY id DESC");
  259. $return = '<table class="aleks_table smaller" width=100% border=0>
  260. <tr class="row-b">
  261. <td class="row-b"></td>
  262. <td class="row-b"><strong>Navn</td>
  263. <td class="row-b"><strong>Status</strong></td>
  264. <td class="row-b"><strong>Eier</strong></td>
  265. <td class="row-b"><strong>Dato</strong></td>
  266. </tr>';
  267. while($r=$fetchList->fetch_assoc())
  268. {
  269. $agent_name = $maestro_db->query("SELECT info_name FROM m3.user_info WHERE uid = {$r['uid']}")->fetch_assoc()['info_name'];
  270. $listname = $r['list_name'];
  271.  
  272. if (strlen($agent_name) > 16)
  273. $agent_name = '<span title="'.$agent_name.'" style="cursor: help;">'.substr($agent_name, 0, 15).'...</span>';
  274.  
  275. if (strlen($listname) > 16)
  276. $listname = '<span title="'.$listname.'" style="cursor: help;">'.substr($listname, 0, 13).'...</span>';
  277.  
  278. if($r['state'] == 'open')
  279. {
  280. $return .= "<tr class='row-c'>
  281. <td nowrap><a href='#' onclick='specificsharedlist({$r['id']}, true);'><img src='/_m3/img/16x16/flip_down.png'></a> <div id='downloadcsv' style='display:inline;'><a href='#' onclick='downloadCsvList({$r['id']});'><img src='img/file_icons/excel.png'></a></td>
  282. <td nowrap><font color='black'>$listname</font></td>
  283. <td nowrap><font color='black'></font></td>
  284. <td nowrap><font color='black'>{$agent_name}</font></td>
  285. <td nowrap><font color='black'>{$r['date']}</font></td>
  286. </tr>";
  287. }
  288. else if ($r['state'] == 'locked')
  289. {
  290. $return .= "<tr class='row-c'>
  291. <td nowrap><a href='#' onclick='specificsharedlist({$r['id']}, false);'><img src='/_m3/img/16x16/flip_down.png'></a> <div id='downloadcsv' style='display:inline;'><a href='#' onclick='downloadCsvList({$r['id']});'><img src='img/file_icons/excel.png'></a></td>
  292. <td nowrap><font color='black'>$listname</font></td>
  293. <td nowrap>".make_html_tooltip('#' , '<img src="img/fugue_icons/lock.png">', 'L���¥st','Listen er l���¥st, du kan derfor ikke legge til rader.',false)."</td>
  294. <td nowrap><font color='black'>{$agent_name}</font></td>
  295. <td nowrap><font color='black'>{$r['date']}</font></td>
  296. </tr>";
  297. }
  298. }
  299. $return.="</table>";
  300. die($return);
  301. break;
  302.  
  303. case "specificsharedlist":
  304. $id=$_POST['id'];
  305. $listname=$maestro_db->query("SELECT * FROM prosjekt.userlists WHERE id='$id'")->fetch_assoc();
  306. $result=$maestro_db->query("SELECT * FROM userlist_management.list_{$id}");
  307. $return = "<table class='aleks_table smaller' width=100% border=0><tr class='row-b'>";
  308. $first=true;
  309. foreach($result as $row)
  310. {
  311. if($first)
  312. {
  313. $return .= "<tr class='row-b'>";
  314. foreach($row as $key => $field)
  315. {
  316. if($key=='id' || $key=='reg_date' || $key=='added_by')
  317. continue;
  318.  
  319. $return .= "<td class='row-b'><strong>". $key ."</strong></td>";
  320. }
  321. $return .= "</tr>";
  322. $first = false;
  323. }
  324. $return .= "<tr>";
  325. foreach($row as $key => $field)
  326. {
  327. if($key=='id' || $key=='reg_date' || $key=='added_by')
  328. continue;
  329.  
  330. $return .= "<td class='row-a' height='16'>".(empty($row[$key]) ? "&nbsp;" : "<font color='black'>{$row[$key]}</font>" )."</td>";
  331. }
  332. $return .= "</tr>";
  333. }
  334. $return .= "</table>";
  335. if($listname['state'] == 'open')
  336. $return .= "<br><div class='addRowShared' style='cursor: pointer'><center><a href='#' onclick='addRowToSharedList({$id});'>Legg til rad</a></center></div>";
  337. else
  338. $return .= "";
  339. die($return);
  340. break;
  341.  
  342. case "addrowtoshared":
  343. $id=$_POST['id'];
  344. $result=$maestro_db->query("SELECT * FROM userlist_management.list_{$id}");
  345. $return = "<table class='aleks_table smaller' width=100% border=0>";
  346. $first=true;
  347. $second=true;
  348. foreach($result as $row)
  349. {
  350. if($first)
  351. {
  352. $return .= "<tr class='row-b'>";
  353. foreach($row as $key => $field)
  354. {
  355. if($key=='id' || $key=='reg_date' || $key=='added_by')
  356. continue;
  357.  
  358. $return .= "<td class='row-b'><strong>". $key ."</strong></td>";
  359. }
  360. $return .= "<td class='row-b'></td></tr>";
  361. $first = false;
  362. }
  363. if($second)
  364. {
  365. $return .= "<tr class='row-a'>";
  366. foreach($row as $key => $field)
  367. {
  368. if($key=='id' || $key=='reg_date' || $key=='added_by')
  369. continue;
  370.  
  371. $return .= "<td><input name={$key} class='newrowtoshared' type='text' value=''/></td>";
  372. }
  373. $return .= "<td><input type='submit' class='fancypants_button fancy_green' value='Lagre' onclick='submitNewRow({$id});' style='float: right;'></td></tr>";
  374. $second = false;
  375. }
  376. }
  377. $return .= "</tr>";
  378. die($return);
  379. break;
  380.  
  381. case "addrowtoprivate":
  382. $id=$_POST['id'];
  383. $result=$maestro_db->query("SELECT * FROM userlist_management.list_{$id}");
  384. $return = "<table class='aleks_table smaller' width=100% border=0>";
  385. $first=true;
  386. $second=true;
  387. if($result->num_rows > 0)
  388. {
  389. foreach($result as $row)
  390. {
  391. if($first)
  392. {
  393. $return .= "<tr class='row-b'>";
  394. foreach($row as $key => $field)
  395. {
  396. if($key=='id' || $key=='reg_date' || $key=='added_by')
  397. continue;
  398.  
  399. $return .= "<td class='row-b'><strong>". $key ."</strong></td>";
  400. }
  401. $return .= "<td class='row-b'></td></tr>";
  402. $first = false;
  403. }
  404. if($second)
  405. {
  406. $return .= "<tr class='row-a'>";
  407. foreach($row as $key => $field)
  408. {
  409. if($key=='id' || $key=='reg_date' || $key=='added_by')
  410. continue;
  411.  
  412. $return .= "<td><input name={$key} class='newrowtoprivate' type='text' value=''/></td>";
  413. }
  414. $return .= "<td><input type='submit' class='fancypants_button fancy_green' value='Lagre' onclick='submitNewRowToPrivate({$id});' style='float: right;'></td></tr>";
  415. $second = false;
  416. }
  417. }
  418. }
  419. else
  420. {
  421. $return .= "<tr class='row-b'>";
  422. $colItems = $maestro_db->query("SHOW COLUMNS FROM userlist_management.list_{$id}");
  423. while($row = $colItems->fetch_assoc())
  424. {
  425. if($row['Field'] == 'id' || $row['Field'] == 'reg_date' || $row['Field'] == 'added_by')
  426. continue;
  427. else
  428. $return .= "<td>{$row['Field']}</td>";
  429. $nextRow .= "<td><input name={$row['Field']} class='newrowtoprivate' type='text' value=''/></td>";
  430. }
  431. $return .= "<td></td></tr><tr class='row-b'>";
  432. $return .= $nextRow;
  433. $return .= "<td><a href='#' onclick='submitNewRowToPrivate({$id});'><strong>Legg til</strong></a></td></tr>";
  434. }
  435. $return .= "</table>";
  436. die($return);
  437. break;
  438.  
  439. case "submitnewrowprivate":
  440. $id=$_POST['id'];
  441. $insert=$_POST['postarray'];
  442. $columnnames="";
  443. $first=true;
  444. while ($row = current($insert))
  445. {
  446. if($first)
  447. {
  448. $columnnames .= "(".key($insert);
  449. $first=false;
  450. }
  451. else
  452. {
  453. $columnnames .= ", ".key($insert);
  454. }
  455. next($insert);
  456. }
  457. $columnnames .= ", added_by) ";
  458. $values="(";
  459. $first=true;
  460. foreach($insert as $row)
  461. {
  462. if($first)
  463. {
  464. $values.="'".$row."'";
  465. $first=false;
  466. }
  467. else
  468. {
  469. $values.=", "."'".$row."'";
  470. }
  471. }
  472. $values.=", '{$_SESSION['uid']}')";
  473. $sql="INSERT INTO userlist_management.list_{$id} {$columnnames} VALUES {$values}";
  474. $maestro_db->query($sql);
  475. if ($maestro_db->error != "")
  476. $return = $maestro_db->error;
  477. else
  478. $return = "success";
  479. die($return);
  480. break;
  481.  
  482. case "submitnewrow":
  483. $id=$_POST['id'];
  484. $insert=$_POST['postarray'];
  485. $columnnames="";
  486. $first=true;
  487. while ($row = current($insert))
  488. {
  489. if($first)
  490. {
  491. $columnnames .= "(".key($insert);
  492. $first=false;
  493. }
  494. else
  495. {
  496. $columnnames .= ", ".key($insert);
  497. }
  498. next($insert);
  499. }
  500. $columnnames .= ")";
  501. $values="(";
  502. $first=true;
  503. foreach($insert as $row)
  504. {
  505. if($first)
  506. {
  507. $values.="'".$row."'";
  508. $first=false;
  509. }
  510. else
  511. {
  512. $values.=", "."'".$row."'";
  513. }
  514. }
  515. $values.=")";
  516. $sql="INSERT INTO userlist_management.list_{$id} {$columnnames} VALUES {$values}";
  517. $maestro_db->query($sql);
  518. if ($maestro_db->error != "")
  519. $return = $maestro_db->error;
  520. else
  521. $return = "success";
  522. die($return);
  523. break;
  524.  
  525. case "changeprivate":
  526. $id=$_POST['id'];
  527. $result=$maestro_db->query("SELECT * FROM prosjekt.userlists WHERE id='$id'")->fetch_assoc();
  528. if($result['private']==0)
  529. $maestro_db->query("UPDATE prosjekt.userlists SET private='1' WHERE id='$id'");
  530. else
  531. $maestro_db->query("UPDATE prosjekt.userlists SET private='0' WHERE id='$id'");
  532. if ($maestro_db->error != "")
  533. $return = $maestro_db->error;
  534. else
  535. $return = "success";
  536. die($return);
  537. break;
  538.  
  539. case "changeopen":
  540. $id=$_POST['id'];
  541. $result=$maestro_db->query("SELECT * FROM prosjekt.userlists WHERE id='$id'")->fetch_assoc();
  542. if($result['state']=='locked')
  543. $maestro_db->query("UPDATE prosjekt.userlists SET state='open' WHERE id='$id'");
  544. else if (($result['state']=='open'))
  545. $maestro_db->query("UPDATE prosjekt.userlists SET state='locked' WHERE id='$id'");
  546. if ($maestro_db->error != "")
  547. $return = $maestro_db->error;
  548. else
  549. $return = "success";
  550. die($return);
  551. break;
  552.  
  553. case "downloadcsv":
  554. $id=$_POST['id'];
  555. $result = $maestro_db->query("SELECT * FROM userlist_management.list_{$id}");
  556. $rows = [];
  557. while($row = $result->fetch_assoc())
  558. {
  559. $rows[] = $row;
  560. }
  561. if ($maestro_db->error != "")
  562. $return = $maestro_db->error;
  563. else
  564. $return = "success";
  565. $csvContent=array2csv($rows);
  566. $file="/var/www/maestro/data/temp.csv";
  567. file_put_contents($file, $csvContent);
  568. die($return);
  569. break;
  570.  
  571. case "fillconfig":
  572. $result=$maestro_db->query("SELECT * FROM prosjekt.userlists WHERE id={$_POST['id']}");
  573. $return = "<table class='aleks_table smaller' border='0'>";
  574. $return .= "<tr class='row-b'><td class='row-b'><strong>Del med:</strong><span><a href='#' onclick=\"popup('popUpDiv')\" ><img src='img/ofm/avslutt.png' style='float: right;'></a></span></td></tr>";
  575. $return .= "<tr nowrap class='row-b'><td nowrap class='row-b'>".make_html_user_checkboxes($_POST['id'])."</td></tr>";
  576. $return .= "<tr class='row-b'><td class='row-b'><input type='button' class='fancypants_button fancy_green' value='Lagre' onclick='saveConfigChanges({$_POST['id']});'></td></tr>";
  577. $return .= "</table>";
  578. die($return);
  579. break;
  580.  
  581. case "saveconfigchanges":
  582. $id=$_POST['id'];
  583. $selected=$_POST['users'];
  584. $sql="UPDATE prosjekt.userlists SET shared_with='{$selected}' WHERE id={$_POST['id']}";
  585. $maestro_db->query($sql);
  586.  
  587. if ($maestro_db->error != "")
  588. $return = $maestro_db->error;
  589. else
  590. $return = "success";
  591. die($return);
  592. break;
  593.  
  594. case "sharedwithme":
  595. $fetchList=$maestro_db->query("SELECT * FROM $listDB WHERE private=1 AND deleted=0 AND shared_with LIKE '%{$_SESSION['uid']}%' ORDER BY id DESC");
  596. $return = '<table class="aleks_table smaller" width=100% border=0>
  597. <tr class="row-b">
  598. <td class="row-b"></td>
  599. <td class="row-b"><strong>Navn</td>
  600. <td class="row-b"><strong>Status</strong></td>
  601. <td class="row-b"><strong>Eier</strong></td>
  602. <td class="row-b"><strong>Dato</strong></td>
  603. </tr>';
  604. while($r=$fetchList->fetch_assoc())
  605. {
  606. $agent_name = $maestro_db->query("SELECT info_name FROM m3.user_info WHERE uid = {$r['uid']}")->fetch_assoc()['info_name'];
  607. $listname = $r['list_name'];
  608. if (strlen($agent_name) > 16)
  609. $agent_name = '<span title="'.$agent_name.'" style="cursor: help;">'.substr($agent_name, 0, 15).'...</span>';
  610. if (strlen($listname) > 16)
  611. $listname = '<span title="'.$listname.'" style="cursor: help;">'.substr($listname, 0, 13).'...</span>';
  612. if($r['state'] == 'open')
  613. {
  614. $return .= "<tr class='row-d'>
  615. <td class='row-c'nowrap><a href='#' onclick='specificsharedlist({$r['id']}, true);'><img src='/_m3/img/16x16/flip_down.png'></a> <div id='downloadcsv' style='display:inline;'><a href='#' onclick='downloadCsvList({$r['id']});'><img src='img/file_icons/excel.png'></a></td>
  616. <td class='row-c'nowrap><font color='black'>$listname</font></td>
  617. <td class='row-c'nowrap><font color='black'>���pen</font></td>
  618. <td class='row-c'nowrap><font color='black'>{$agent_name}</font></td>
  619. <td class='row-c'nowrap><font color='black'>{$r['date']}</font></td>
  620. </tr>";
  621. }
  622. else if ($r['state'] == 'locked')
  623. {
  624. $return .= "<tr class='row-d'>
  625. <td class='row-c'nowrap><a href='#' onclick='specificsharedlist({$r['id']}, false);'><img src='/_m3/img/16x16/flip_down.png'></a> <div id='downloadcsv' style='display:inline;'><a href='#' onclick='downloadCsvList({$r['id']});'><img src='img/file_icons/excel.png'></a></td>
  626. <td class='row-c'nowrap><font color='black'>$listname</font></td>
  627. <td class='row-c'nowrap><img src='img/fugue_icons/lock.png'></td>
  628. <td class='row-c'nowrap><font color='black'>{$agent_name}</font></td>
  629. <td class='row-c'nowrap><font color='black'>{$r['date']}</font></td>
  630. </tr>";
  631. }
  632. }
  633. $return.="</table>";
  634. die($return);
  635. break;
  636.  
  637. case "getarchived":
  638. $fetchList=$maestro_db->query("SELECT * FROM $listDB WHERE deleted=1 AND uid={$_SESSION['uid']}");
  639. $return = '<table class="aleks_table smaller" width=100% border=0>
  640. <tr class="row-b">
  641. <td class="row-b"></td>
  642. <td class="row-b"><strong>Navn</td>
  643. <td class="row-b"><strong>Dato</strong></td>
  644. </tr>';
  645. while($r=$fetchList->fetch_assoc())
  646. {
  647. $listname = $r['list_name'];
  648. if (strlen($listname) > 16)
  649. $listname = '<span title="'.$listname.'" style="cursor: help;">'.substr($listname, 0, 13).'...</span>';
  650. $return .= "<tr class='row-d'>
  651. <td class='row-c'nowrap><a href='#' onclick='restorelist({$r['id']});'><img src='/_m3/img/16x16/flip_up.png'></a> </td>
  652. <td class='row-c'nowrap><font color='black'>$listname</font></td>
  653. <td class='row-c'nowrap><font color='black'>{$r['date']}</font></td>
  654. </tr>";
  655.  
  656. }
  657. $return.="</table>";
  658. die($return);
  659. break;
  660.  
  661. case "restorelist":
  662. $id=$_POST['id'];
  663. $maestro_db->query("UPDATE prosjekt.userlists SET deleted=0 WHERE id='$id'");
  664.  
  665. if ($maestro_db->error != "")
  666. $return = $maestro_db->error;
  667. else
  668. $return = "success";
  669.  
  670. die($return);
  671. break;
  672. }
  673. die();
  674. }
  675. ?>
  676. <style>
  677. #blanket
  678. {
  679. background-color:#111;
  680. opacity: 0.65;
  681. *background:none;
  682. position:absolute;
  683. z-index: 9001;
  684. top:0px;
  685. left:0px;
  686. width:100%;
  687. }
  688. #popUpDiv
  689. {
  690. background-color: #000000;
  691. position:absolute;
  692. width:214px;
  693. height:0px;
  694. z-index: 9002;
  695. margin:-100px 0 0 -150px;
  696. top:50%;
  697. left:50%;
  698. }
  699. </style>
  700. <?php
  701. if(!isset($_GET['p']))
  702. {
  703. echo "<h1>Maestro brukerlister</h1>
  704. <table class='aleks_table smaller' width=100% border=0><tr class='row-b'><td class='row-b'><strong>Meny</strong></td></tr><tr><td class='row-a'><input type='submit' class='fancypants_button fancy_darkgray' value='Mine lister' onclick='update_userlists();'> <input type='submit' class='fancypants_button fancy_darkgray' value='Delte lister' onclick='update_sharedlists();'> <input type='submit' class='fancypants_button fancy_darkgray' value='Delt med meg' onclick='sharedwithme();'> <input type='submit' class='fancypants_button fancy_darkgray' value='Opprett' onclick='make_list();'> <input type='submit' class='fancypants_button fancy_green' value='Arkiv' onclick='update_archive();' style='float:right;'></td></strong></tr></table>
  705. <div id=userlists style='margin: 10px 0 10px 0;'></div>
  706. <div id=addRow style='margin: 10px 0 10px 0;'></div>
  707. <div id=userspecific style='margin: 10px 0 10px 0;'></div>";
  708. }
  709.  
  710. function clean($string)
  711. {
  712. $string = str_replace(' ', '', $string);
  713. $string = str_replace('-', '', $string);
  714. return preg_replace('/[^A-Za-z0-9\-]/', '', $string);
  715. }
  716. function array2csv(array &$array)
  717. {
  718. if (count($array) == 0)
  719. return null;
  720.  
  721. ob_start();
  722. $df = fopen("php://output", 'w');
  723. fputcsv($df, array_keys(reset($array)));
  724.  
  725. foreach ($array as $row)
  726. fputcsv($df, $row);
  727.  
  728. fclose($df);
  729. return ob_get_clean();
  730. }
  731. function make_html_user_checkboxes($id)
  732. {
  733. global $maestro_db;
  734. $result = $maestro_db->query("SELECT * FROM user_info JOIN user ON user.active='yes' AND user.uid=user_info.uid ORDER BY info_name");
  735. $checkExsisting=$maestro_db->query("SELECT shared_with FROM prosjekt.userlists WHERE id='$id'")->fetch_assoc();
  736. $exploded=explode(",", $checkExsisting['shared_with']);
  737. $return="";
  738. while($row=$result->fetch_assoc())
  739. {
  740. if(in_array($row['uid'],$exploded))
  741. $return.="<input type='checkbox' name='{$row['info_name']}' value='{$row['uid']}' checked> {$row['info_name']}<br>";
  742. else
  743. $return.="<input type='checkbox' name='{$row['info_name']}' value='{$row['uid']}'> {$row['info_name']}<br>";
  744. }
  745. return $return;
  746. }
  747. ?>
  748.  
  749. <div id="blanket" style="display:none;"></div>
  750. <div id="popUpDiv" style="display:none;">
  751. <div id="popUpDivContent"></div>
  752. </div>
  753. <script src="/_m3/src/functions.js"></script>
  754. <script type="text/javascript">
  755. function restorelist(id)
  756. {
  757. $.post("/_m3/html/view_userlist.php",
  758. {
  759. action:"restorelist",
  760. id:id
  761. },
  762. function(data)
  763. {
  764. if(data == 'success')
  765. {
  766. toastr.success("Fullf���¸rt","Listen er gjenopprettet!");
  767. update_userlists();
  768. }
  769. else
  770. {
  771. toastr.error(data);
  772. update_userlists();
  773. }
  774. }
  775. );
  776. }
  777. function update_archive()
  778. {
  779. $.post("/_m3/html/view_userlist.php",
  780. {
  781. action:"getarchived"
  782. },
  783. function(data)
  784. {
  785. $("#userlists").html(data);
  786. $("#userspecific").html("");
  787. $("#addRow").html("");
  788. }
  789. );
  790. }
  791. function sharedwithme()
  792. {
  793. $.post("/_m3/html/view_userlist.php",
  794. {
  795. action:"sharedwithme"
  796. },
  797. function(data)
  798. {
  799. $("#userlists").html(data);
  800. $("#userspecific").html("");
  801. $("#addRow").html("");
  802. }
  803. );
  804. }
  805. function saveConfigChanges(id)
  806. {
  807. var users = "";
  808. var first=true;
  809. $( "input:checked" ).each(function()
  810. {
  811. if(first==true)
  812. {
  813. users += $( this ).val();
  814. first=false;
  815. }
  816. else
  817. {
  818. users += "," + $( this ).val();
  819. }
  820. });
  821.  
  822. $.post("/_m3/html/view_userlist.php",
  823. {
  824. action:"saveconfigchanges",
  825. id:id,
  826. users:users
  827. },
  828. function(data)
  829. {
  830. if(data == 'success')
  831. {
  832. toastr.success("Lagret","Endringene er lagret!");
  833. popup('popUpDiv');
  834. }
  835. else
  836. {
  837. toastr.error(data);
  838. popup('popUpDiv');
  839. }
  840. }
  841. );
  842. }
  843. function toggle(div_id)
  844. {
  845. var el = document.getElementById(div_id);
  846. if ( el.style.display == 'none' ) { el.style.display = 'block';}
  847. else {el.style.display = 'none';}
  848. }
  849. function blanket_size(popUpDivVar)
  850. {
  851. if (typeof window.innerWidth != 'undefined') {
  852. viewportheight = window.innerHeight;
  853. }
  854. else
  855. {
  856. viewportheight = document.documentElement.clientHeight;
  857. }
  858. if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight))
  859. {
  860. blanket_height = viewportheight;
  861. }
  862. else
  863. {
  864. if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight)
  865. {
  866. blanket_height = document.body.parentNode.clientHeight;
  867. }
  868. else
  869. {
  870. blanket_height = document.body.parentNode.scrollHeight;
  871. }
  872. }
  873. var blanket = document.getElementById('blanket');
  874. blanket.style.height = blanket_height + 'px';
  875. var popUpDiv = document.getElementById(popUpDivVar);
  876. popUpDiv_height=blanket_height/2-700;//200 is half popup's height
  877. popUpDiv.style.top = popUpDiv_height + 'px';
  878. }
  879. function window_pos(popUpDivVar)
  880. {
  881. if (typeof window.innerWidth != 'undefined')
  882. {
  883. viewportwidth = window.innerHeight;
  884. }
  885. else
  886. {
  887. viewportwidth = document.documentElement.clientHeight;
  888. }
  889. if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth))
  890. {
  891. window_width = viewportwidth;
  892. }
  893. else
  894. {
  895. if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth)
  896. {
  897. window_width = document.body.parentNode.clientWidth;
  898. }
  899. else
  900. {
  901. window_width = document.body.parentNode.scrollWidth;
  902. }
  903. }
  904. var popUpDiv = document.getElementById(popUpDivVar);
  905. window_width=window_width/2-200;//200 is half popup's width
  906. popUpDiv.style.left = window_width + 'px';
  907. }
  908. function popup(windowname, id)
  909. {
  910. $.post("/_m3/html/view_userlist.php",
  911. {
  912. action:"fillconfig",
  913. id:id
  914. },
  915. function(data)
  916. {
  917. $("#popUpDivContent").html(data);
  918. }
  919. );
  920. blanket_size(windowname);
  921. window_pos(windowname);
  922. toggle('blanket');
  923. toggle(windowname);
  924. }
  925. function update_userlists()
  926. {
  927. $.post("/_m3/html/view_userlist.php",
  928. {
  929. action:"getlist"
  930. },
  931. function(data)
  932. {
  933. $("#userlists").html(data);
  934. $("#userspecific").html("");
  935. $("#addRow").html("");
  936. $(".listname").off("dblclick", dblclickfunction);
  937. $(".listname").dblclick(dblclickfunction);
  938. }
  939. );
  940. }
  941. function downloadCsvList(id)
  942. {
  943. $.post("/_m3/html/view_userlist.php",
  944. {
  945. action:"downloadcsv",
  946. id:id
  947. },
  948. function(data)
  949. {
  950. if(data == 'success')
  951. {
  952. $("#downloadcsv").html("<a href='data/temp.csv'><img src='img/file_icons/excel.png'></a>");
  953. toastr.success("Fil opprettet","Trykk en gang til for ���¥ laste ned filen til maskinen!");
  954. }
  955. else
  956. {
  957. toastr.error(data);
  958. }
  959. }
  960. );
  961. }
  962. function changeOpen(id)
  963. {
  964. $.post("/_m3/html/view_userlist.php",
  965. {
  966. action:"changeopen",
  967. id:id
  968. },
  969. function(data)
  970. {
  971. if(data == 'success')
  972. {
  973. toastr.success("Lagret","Endringene er lagret!");
  974. update_userlists();
  975. }
  976. else
  977. {
  978. toastr.error(data);
  979. update_userlists();
  980. }
  981. }
  982. );
  983. }
  984. function changePrivate(id)
  985. {
  986. $.post("/_m3/html/view_userlist.php",
  987. {
  988. action:"changeprivate",
  989. id:id
  990. },
  991. function(data)
  992. {
  993. if(data == 'success')
  994. {
  995. toastr.success("Lagret","Endringene er lagret!");
  996. update_userlists();
  997. }
  998. else
  999. {
  1000. toastr.error(data);
  1001. update_userlists();
  1002. }
  1003. }
  1004. );
  1005. }
  1006. function deleteRow(rowid, id)
  1007. {
  1008. if (confirm("Er du sikker p���¥ at du vil slette denne raden?"))
  1009. {
  1010. $.post("/_m3/html/view_userlist.php",
  1011. {
  1012. action:"deleteprivaterow",
  1013. id:id,
  1014. rowid:rowid
  1015. },
  1016. function(data)
  1017. {
  1018. if(data == "success")
  1019. {
  1020. toastr.success("Slettet", "Raden er slettet.");
  1021. specificlist(id);
  1022. }
  1023. else
  1024. {
  1025. toastr.error("Feil", data);
  1026. }
  1027. }
  1028. );
  1029. }
  1030. }
  1031. function addRowToList(id)
  1032. {
  1033. $.post("/_m3/html/view_userlist.php",
  1034. {
  1035. action:"addrowtoprivate",
  1036. id: id
  1037. },
  1038. function(data)
  1039. {
  1040. $("#addRow").html(data);
  1041. $(".addRowPrivate").html("");
  1042. }
  1043. );
  1044. }
  1045. function addRowToSharedList(id)
  1046. {
  1047. $.post("/_m3/html/view_userlist.php",
  1048. {
  1049. action:"addrowtoshared",
  1050. id: id
  1051. },
  1052. function(data)
  1053. {
  1054. $("#addRow").html(data);
  1055. $(".addRowShared").html("");
  1056. }
  1057. );
  1058. }
  1059. function submitNewRowToPrivate(id)
  1060. {
  1061. var postobject={};
  1062. $('.newrowtoprivate').each(function()
  1063. {
  1064. postobject[this.name] = this.value;
  1065. });
  1066. $.post("/_m3/html/view_userlist.php",
  1067. {
  1068. action:"submitnewrowprivate",
  1069. id: id,
  1070. postarray:postobject
  1071. },
  1072. function(data)
  1073. {
  1074. if(data == "success")
  1075. {
  1076. toastr.success("Lagret", "Raden er lagret i tabellen.");
  1077. specificlist(id);
  1078. }
  1079. else
  1080. {
  1081. toastr.error("Feil", data);
  1082. specificlist(id);
  1083. }
  1084. }
  1085. );
  1086. }
  1087. function submitNewRow(id)
  1088. {
  1089. var postobject={};
  1090. $('.newrowtoshared').each(function()
  1091. {
  1092. postobject[this.name] = this.value;
  1093. });
  1094. $.post("/_m3/html/view_userlist.php",
  1095. {
  1096. action:"submitnewrow",
  1097. id: id,
  1098. postarray:postobject
  1099. },
  1100. function(data)
  1101. {
  1102. if(data == "success")
  1103. {
  1104. toastr.success("Lagret", "Raden er lagret i tabellen.");
  1105. specificsharedlist(id, true);
  1106. }
  1107. else
  1108. {
  1109. toastr.error("Feil", data);
  1110. specificsharedlist(id, false); // Fortsett
  1111. }
  1112. }
  1113. );
  1114. }
  1115. function update_sharedlists()
  1116. {
  1117. $.post("/_m3/html/view_userlist.php",
  1118. {
  1119. action:"getsharedlists"
  1120. },
  1121. function(data)
  1122. {
  1123. $("#userlists").html(data);
  1124. $("#userspecific").html("");
  1125. $("#addRow").html("");
  1126. }
  1127. );
  1128. }
  1129. function addcolumn()
  1130. {
  1131. $("#newlist > tbody:first-child").append('<tr class="row-a"><td><font color="black"><div class="columnname" style="cursor: pointer">Kolonnenavn</div></font></td></tr>');
  1132. }
  1133. var originalListId;
  1134. function specificlist(id)
  1135. {
  1136. originalListId = id;
  1137. $.post("/_m3/html/view_userlist.php",
  1138. {
  1139. action:"specificlist",
  1140. id:id
  1141. },
  1142. function(data)
  1143. {
  1144. if(data != "wronguid")
  1145. {
  1146. $("#userspecific").html(data);
  1147. $("#addRow").html("");
  1148. $(".addRowprivate").html("");
  1149. $(".editlist").off("dblclick", dblclickeditfunction);
  1150. $(".editlist").dblclick(dblclickeditfunction);
  1151. $(".editheader").off("dblclick", dblclickeditheaderfunction);
  1152. $(".editheader").dblclick(dblclickeditheaderfunction);
  1153. addRowToList(id);
  1154. }
  1155. else
  1156. {
  1157. toastr.error("Feil", "Session error, kontakt systemansvalig.");
  1158. }
  1159. }
  1160. );
  1161. }
  1162. var originalSharedListId;
  1163. function specificsharedlist(id, open)
  1164. {
  1165. originalSharedListId=id;
  1166. $.post("/_m3/html/view_userlist.php",
  1167. {
  1168. action:"specificsharedlist",
  1169. id:id
  1170. },
  1171. function(data)
  1172. {
  1173. if(open===true)
  1174. {
  1175. $("#userspecific").html(data);
  1176. addRowToSharedList(id);
  1177. }
  1178. else
  1179. {
  1180. $("#userspecific").html(data);
  1181. $("#addRow").html("");
  1182. }
  1183. }
  1184. );
  1185. }
  1186. function deletelist(id)
  1187. {
  1188. if (confirm("Er du sikker p���¥ at du vil slette denne listen?"))
  1189. {
  1190. $.post("/_m3/html/view_userlist.php",
  1191. {
  1192. action:"deletelist",
  1193. id:id
  1194. },
  1195. function(data)
  1196. {
  1197. if(data == "success")
  1198. {
  1199. toastr.success("Slettet","Listen ble slettet!");
  1200. update_userlists();
  1201. }
  1202. else if(data == "wronguid")
  1203. {
  1204. toastr.error("Feil", "Session error, kontakt systemansvalig.");
  1205. }
  1206. else
  1207. {
  1208. toastr.error("Feil", data);
  1209. }
  1210. }
  1211. );
  1212. }
  1213. return false;
  1214. }
  1215. function savelist()
  1216. {
  1217. var counter=1;
  1218. var total=$('#newlist tr').length-2;
  1219. var postarray=[];
  1220. $('#newlist > tbody > tr:not("#addcolumn, #savelist, #listoptions")').each(function()
  1221. {
  1222. postarray.push($(this).text());
  1223. counter++;
  1224. });
  1225. if(document.getElementById('private').checked)
  1226. var private=1;
  1227. else
  1228. var private=0;
  1229. $.post("/_m3/html/view_userlist.php",
  1230. {
  1231. action:"savelist",
  1232. columns:postarray,
  1233. private:private
  1234. },
  1235. function(data)
  1236. {
  1237. if(data == "success")
  1238. {
  1239. toastr.success("Lagret","Listen er lagret.");
  1240. update_userlists();
  1241. }
  1242. else
  1243. {
  1244. toastr.error("Feil", data);
  1245. }
  1246. }
  1247. );
  1248. }
  1249. function make_list()
  1250. {
  1251. $("#userspecific").html("");
  1252. $.post("/_m3/html/view_userlist.php",
  1253. {
  1254. action:"make_new_list"
  1255. },
  1256. function(data)
  1257. {
  1258. $("#userlists").html(data);
  1259. $("#userspecific").html("");
  1260. $("#addRow").html("");
  1261. $(".columnname").off("dblclick", dblclickColumnNameFunction);
  1262. $(".columnname").dblclick(dblclickColumnNameFunction);
  1263. }
  1264. );
  1265. }
  1266. var dblclickeditheaderfunction = function(e)
  1267. {
  1268. e.stopPropagation();
  1269. var currentEle = $(this);
  1270. $(document).off('dblclick', '.editheader', dblclickeditheaderfunction);
  1271. currentEle.off("dblclick", dblclickeditheaderfunction);
  1272. var value = $(this).html();
  1273. var id = $(this).attr('id');
  1274. var updateVal = function()
  1275. {
  1276. $(currentEle).html('<input class="thVal" type="text" value="' + value + '" />');
  1277. $(".thVal").focus();
  1278. $(".thVal").keyup(function (event)
  1279. {
  1280. if (event.keyCode == 13)
  1281. saveInput(e);
  1282. });
  1283. $(document).on("click",saveInput);
  1284. };
  1285. var saveInput = function(e)
  1286. {
  1287. if ($(e.target).parent().is(currentEle)) { return; }
  1288. var newval=($(".thVal").val().trim());
  1289. currentEle.html(newval);
  1290. $(document).off("click",saveInput);
  1291. currentEle.dblclick(dblclickeditheaderfunction);
  1292. $(document).on('dblclick', '.editheader', dblclickeditheaderfunction);
  1293. if(newval != value)
  1294. {
  1295. console.log(header);
  1296. $.post("/_m3/html/view_userlist.php",
  1297. {
  1298. action:"update_specific_header",
  1299. rowid:id,
  1300. originalid:originalListId,
  1301. newname:newval,
  1302. value:value
  1303. },
  1304. function(data)
  1305. {
  1306. if(data == "success")
  1307. {
  1308. toastr.success("Lagret","Endringer er lagret!");
  1309. specificlist(originalListId);
  1310. }
  1311. else if(data == "wronguid")
  1312. {
  1313. toastr.error("Feil", "Session error, kontakt systemansvalig.");
  1314. specificlist(originalListId);
  1315. }
  1316. else
  1317. {
  1318. toastr.error("Feil", data);
  1319. specificlist(originalListId);
  1320. }
  1321. }
  1322. );
  1323. }
  1324. }
  1325. updateVal();
  1326. };
  1327. var dblclickeditfunction = function(e)
  1328. {
  1329. e.stopPropagation();
  1330. var currentEle = $(this);
  1331. $(document).off('dblclick', '.editlist', dblclickeditfunction);
  1332. currentEle.off("dblclick", dblclickeditfunction);
  1333. var value = $(this).html();
  1334. var id = $(this).attr('id');
  1335. var header = $(this).attr('name');
  1336. var updateVal = function()
  1337. {
  1338. $(currentEle).html('<input class="thVal" type="text" value="' + value + '" />');
  1339. $(".thVal").focus();
  1340. $(".thVal").keyup(function (event)
  1341. {
  1342. if (event.keyCode == 13)
  1343. saveInput(e);
  1344. });
  1345. $(document).on("click",saveInput);
  1346. };
  1347. var saveInput = function(e)
  1348. {
  1349. if ($(e.target).parent().is(currentEle)) { return; }
  1350. var newval=($(".thVal").val().trim());
  1351. currentEle.html(newval);
  1352. $(document).off("click",saveInput);
  1353. currentEle.dblclick(dblclickeditfunction);
  1354. $(document).on('dblclick', '.editlist', dblclickeditfunction);
  1355. if(newval != value)
  1356. {
  1357. console.log(header);
  1358. $.post("/_m3/html/view_userlist.php",
  1359. {
  1360. action:"update_specific_list",
  1361. rowid:id,
  1362. originalid:originalListId,
  1363. newname:newval,
  1364. header:header,
  1365. value:value
  1366. },
  1367. function(data)
  1368. {
  1369. if(data == "success")
  1370. {
  1371. toastr.success("Lagret","Endringer er lagret!");
  1372. specificlist(originalListId);
  1373. }
  1374. else if(data == "wronguid")
  1375. {
  1376. toastr.error("Feil", "Session error, kontakt systemansvalig.");
  1377. specificlist(originalListId);
  1378. }
  1379. else
  1380. {
  1381. toastr.error("Feil", data);
  1382. specificlist(originalListId);
  1383. }
  1384. }
  1385. );
  1386. }
  1387. }
  1388. updateVal();
  1389. };
  1390. var dblclickfunction = function (e)
  1391. {
  1392. e.stopPropagation();
  1393. var currentEle = $(this);
  1394. currentEle.off("dblclick", dblclickfunction);
  1395. var value = $(this).html();
  1396. var id = $(this).attr('id');
  1397. var updateVal = function()
  1398. {
  1399. $(currentEle).html('<input class="thVal" type="text" value="' + value + '" />');
  1400. $(".thVal").focus();
  1401. $(".thVal").keyup(function (event)
  1402. {
  1403. if (event.keyCode == 13)
  1404. saveInput(e);
  1405. });
  1406. $(document).on("click",saveInput);
  1407. };
  1408. var saveInput = function(e)
  1409. {
  1410. if ($(e.target).parent().is(currentEle)) { return; }
  1411. var newval=($(".thVal").val().trim());
  1412. newval = newval.replace(/'/g, '');
  1413. newval = newval.replace(/"/g, '');
  1414. var validName=false;
  1415. if (!isNaN(newval) || newval.indexOf('\'') >= 0 && newval.indexOf('"') >= 0 || newval == "")
  1416. {
  1417. toastr.error("Feil", "Du m���¥ kalle listen for noe annet.");
  1418. currentEle.html(value);
  1419. }
  1420. else
  1421. {
  1422. validName=true;
  1423. currentEle.html(newval);
  1424. }
  1425. $(document).off("click",saveInput);
  1426. currentEle.dblclick(dblclickfunction);
  1427. if(newval != value && validName==true)
  1428. {
  1429. $.post("/_m3/html/view_userlist.php",
  1430. {
  1431. action:"change_list_name",
  1432. listid:id,
  1433. newname:newval
  1434. },
  1435. function(data)
  1436. {
  1437. if(data == "success")
  1438. {
  1439. toastr.success("Lagret","Navnet er endret!");
  1440. }
  1441. else if(data == "invalid")
  1442. {
  1443. toastr.error("Ugyldig navn", "Fikk ikke endret navn p���¥ liste, fors���¸k med et annet navn");
  1444. update_userlists();
  1445. }
  1446. else if(data == "wronguid")
  1447. {
  1448. toastr.error("Feil", "Session error, kontakt systemansvalig.");
  1449. }
  1450. else
  1451. {
  1452. toastr.error("Feil", "Fikk ikke endret navn p���¥ liste.");
  1453. update_userlists();
  1454. }
  1455. }
  1456. );
  1457. }
  1458. }
  1459. updateVal();
  1460. };
  1461. var dblclickColumnNameFunction=function(e)
  1462. {
  1463. e.stopPropagation();
  1464. var currentEle = $(this);
  1465. $(document).off('dblclick', '.columnname', dblclickColumnNameFunction);
  1466. currentEle.off("dblclick", dblclickColumnNameFunction);
  1467. var value = $(this).html();
  1468. var updateVal = function()
  1469. {
  1470. $(currentEle).html('<input class="thVal" type="text" value="' + value + '" />');
  1471. $(".thVal").focus();
  1472. $(".thVal").keyup(function (event)
  1473. {
  1474. if (event.keyCode == 13)
  1475. saveInput(e);
  1476. });
  1477. $(document).on("click",saveInput);
  1478. };
  1479. var saveInput = function(e)
  1480. {
  1481. if ($(e.target).parent().is(currentEle)) { return; }
  1482. var newval=($(".thVal").val().trim());
  1483. newval = newval.replace(/'/g, '');
  1484. newval = newval.replace(/"/g, '');
  1485. var validName=false;
  1486. if (!isNaN(newval) || newval.indexOf('\'') >= 0 && newval.indexOf('"') >= 0 || newval == "")
  1487. {
  1488. toastr.error("Feil", "Du m���¥ kalle kolonnen for noe annet.");
  1489. currentEle.html(value);
  1490. }
  1491. else
  1492. {
  1493. validName=true;
  1494. currentEle.html(newval);
  1495. }
  1496. $(document).off("click",saveInput);
  1497. currentEle.dblclick(dblclickColumnNameFunction);
  1498. $(document).on('dblclick', '.columnname', dblclickColumnNameFunction);
  1499. }
  1500. updateVal();
  1501. };
  1502. $(function ()
  1503. {
  1504. $(".editheader").dblclick(dblclickeditheaderfunction);
  1505. $(".listname").dblclick(dblclickfunction);
  1506. $(".columnname").dblclick(dblclickColumnNameFunction);
  1507. $(".editlist").dblclick(dblclickeditfunction);
  1508. });
  1509. </script>

Report this snippet  

You need to login to post a comment.