Guest User

Untitled

a guest
Sep 23rd, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 108.09 KB | None | 0 0
  1. <?php
  2. /*
  3. * Xibo - Digitial Signage - http://www.xibo.org.uk
  4. * Copyright (C) 2006-2012 Daniel Garner and James Packer
  5. *
  6. * This file is part of Xibo.
  7. *
  8. * Xibo is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * any later version.
  12. *
  13. * Xibo is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with Xibo. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. defined('XIBO') or die("Sorry, you are not allowed to directly access this page.<br /> Please press the back button in your browser.");
  22.  
  23. class layoutDAO
  24. {
  25. private $db;
  26. private $user;
  27. private $auth;
  28. private $has_permissions = true;
  29.  
  30. private $sub_page = "";
  31.  
  32. private $layoutid;
  33. private $layout;
  34. private $retired;
  35. private $description;
  36. private $tags;
  37.  
  38. private $xml;
  39.  
  40. /**
  41. * Layout Page Logic
  42. * @return
  43. * @param $db Object
  44. */
  45. function __construct(database $db, user $user)
  46. {
  47. $this->db =& $db;
  48. $this->user =& $user;
  49.  
  50. $this->sub_page = Kit::GetParam('sp', _GET, _WORD, 'view');
  51. $this->layoutid = Kit::GetParam('layoutid', _REQUEST, _INT);
  52.  
  53. // Include the layout data class
  54. include_once("lib/data/layout.data.class.php");
  55.  
  56. //if we have modify selected then we need to get some info
  57. if ($this->layoutid != '')
  58. {
  59. // get the permissions
  60. Debug::LogEntry($db, 'audit', 'Loading permissions for layoutid ' . $this->layoutid);
  61.  
  62. $this->auth = $user->LayoutAuth($this->layoutid, true);
  63.  
  64. if (!$this->auth->edit)
  65. trigger_error(__("You do not have permissions to edit this layout"), E_USER_ERROR);
  66.  
  67. $this->sub_page = "edit";
  68. $this->arrows=1;
  69.  
  70. $sql = " SELECT layout, description, userid, retired, tags, xml FROM layout ";
  71. $sql .= sprintf(" WHERE layoutID = %d ", $this->layoutid);
  72.  
  73. if(!$results = $db->query($sql))
  74. {
  75. trigger_error($db->error());
  76. trigger_error(__("Cannot retrieve the Information relating to this layout. The layout may be corrupt."), E_USER_ERROR);
  77. }
  78.  
  79. if ($db->num_rows($results) == 0)
  80. $this->has_permissions = false;
  81.  
  82. while($aRow = $db->get_row($results))
  83. {
  84. $this->layout = Kit::ValidateParam($aRow[0], _STRING);
  85. $this->description = Kit::ValidateParam($aRow[1], _STRING);
  86. $this->retired = Kit::ValidateParam($aRow[3], _INT);
  87. $this->tags = Kit::ValidateParam($aRow[4], _STRING);
  88. $this->xml = $aRow[5];
  89. }
  90. }
  91. }
  92.  
  93. function on_page_load()
  94. {
  95. return "";
  96. }
  97.  
  98. function echo_page_heading()
  99. {
  100. echo __("Layouts");
  101. return true;
  102. }
  103.  
  104. function displayPage()
  105. {
  106. $db =& $this->db;
  107.  
  108. switch ($this->sub_page)
  109. {
  110. case 'view':
  111. require("template/pages/layout_view.php");
  112. break;
  113.  
  114. case 'edit':
  115. require("template/pages/layout_edit.php");
  116. break;
  117.  
  118. default:
  119. break;
  120. }
  121.  
  122. return false;
  123. }
  124.  
  125. function LayoutFilter()
  126. {
  127. $db =& $this->db;
  128. $user =& $this->user;
  129.  
  130. $layout = ""; //3
  131. if (isset($_SESSION['layout']['filter_layout'])) $layout = $_SESSION['layout']['filter_layout'];
  132.  
  133. //retired list
  134. $retired = "0";
  135. if(isset($_SESSION['layout']['filter_retired'])) $retired = $_SESSION['layout']['retired'];
  136. $retired_list = listcontent("all|All,1|Yes,0|No","filter_retired",$retired);
  137.  
  138. //owner list
  139. $filter_userid = "";
  140.  
  141. $SQL = "SELECT layout.layoutID, layout.userID, user.UserName FROM layout INNER JOIN user ON layout.userID = user.UserID ORDER BY userID";
  142. if (!$results = $db->query($SQL))
  143. {
  144. trigger_error($db->error());
  145. trigger_error(__("Can not get layout information"), E_USER_ERROR);
  146. }
  147. $ulist = '';
  148. $uid = 0;
  149. while($Row = $db->get_row($results))
  150. {
  151. //get the query results
  152. $layoutId = Kit::ValidateParam($Row[0], _INT);
  153. $userId = Kit::ValidateParam($Row[1], _INT);
  154. $userName = Kit::ValidateParam($Row[2], _STRING);
  155.  
  156. // Permissions
  157. $auth = $this->user->LayoutAuth($layoutId, true);
  158.  
  159. if ($auth->view && $uid != $userId)
  160. {
  161. $uid = $userId;
  162. $ulist = $ulist . $userId . '|' . $userName . ',';
  163. }
  164. }
  165. $ulist = rtrim($ulist, ',');
  166.  
  167.  
  168. if(isset($_SESSION['layout']['filter_userid'])) $filter_userid = $_SESSION['layout']['filter_userid'];
  169. $user_list = listcontent("all|All,".$ulist,"filter_userid", $filter_userid);
  170.  
  171. //tags list
  172. $filter_tags = "";
  173. if(isset($_SESSION['layout']['filter_tags'])) $filter_tags = $_SESSION['layout']['filter_tags'];
  174.  
  175. $msgName = __('Name');
  176. $msgOwner = __('Owner');
  177. $msgTags = __('Tags');
  178. $msgRetired = __('Retired');
  179.  
  180. $filterForm = <<<END
  181. <div class="FilterDiv" id="LayoutFilter">
  182. <form onsubmit="return false">
  183. <input type="hidden" name="p" value="layout">
  184. <input type="hidden" name="q" value="LayoutGrid">
  185.  
  186. <table class="layout_filterform">
  187. <tr>
  188. <td>$msgName</td>
  189. <td><input class="form-control" type="text" name="filter_layout"></td>
  190. <td>$msgOwner</td>
  191. <td>$user_list</td>
  192. </tr>
  193. <tr>
  194. <td>$msgTags</td>
  195. <td><input class="form-control" type="text" name="filter_tags" value="$filter_tags" /></td>
  196. <td>$msgRetired</td>
  197. <td>$retired_list</td>
  198. </tr>
  199. </table>
  200. </form>
  201. </div>
  202. END;
  203.  
  204. $id = uniqid();
  205.  
  206. $xiboGrid = <<<HTML
  207. <div class="XiboGrid" id="$id">
  208. <div class="XiboFilter">
  209. $filterForm
  210. </div>
  211. <div class="XiboData">
  212.  
  213. </div>
  214. </div>
  215. HTML;
  216. echo $xiboGrid;
  217. }
  218.  
  219.  
  220. /**
  221. * Adds a layout record to the db
  222. * @return
  223. */
  224. function add()
  225. {
  226. $db =& $this->db;
  227. $response = new ResponseManager();
  228.  
  229. $layout = Kit::GetParam('layout', _POST, _STRING);
  230. $description = Kit::GetParam('description', _POST, _STRING);
  231. $tags = Kit::GetParam('tags', _POST, _STRING);
  232. $templateId = Kit::GetParam('templateid', _POST, _INT, 0);
  233. $userid = Kit::GetParam('userid', _SESSION, _INT);
  234.  
  235. // Add this layout
  236. $layoutObject = new Layout($db);
  237.  
  238. if(!$id = $layoutObject->Add($layout, $description, $tags, $userid, $templateId))
  239. {trigger_error($layoutObject->GetErrorMessage(), E_USER_ERROR);}
  240.  
  241. // Successful layout creation
  242. $response->SetFormSubmitResponse(__('Layout Details Changed.'), true, sprintf("index.php?p=layout&layoutid=%d&modify=true", $id));
  243. $response->callBack = 'XiboDialogClose';
  244. $response->Respond();
  245. }
  246.  
  247. /**
  248. * Modifies a layout record
  249. *
  250. * @param int $id
  251. */
  252. function modify ()
  253. {
  254. $db =& $this->db;
  255. $response = new ResponseManager();
  256.  
  257. $layout = Kit::GetParam('layout', _POST, _STRING);
  258. $description = Kit::GetParam('description', _POST, _STRING);
  259. $tags = Kit::GetParam('tags', _POST, _STRING);
  260. $retired = Kit::GetParam('retired', _POST, _INT, 0);
  261.  
  262. $userid = Kit::GetParam('userid', _SESSION, _INT);
  263. $currentdate = date("Y-m-d H:i:s");
  264.  
  265. //validation
  266. if (strlen($layout) > 50 || strlen($layout) < 1)
  267. {
  268. $response->SetError(__("Layout Name must be between 1 and 50 characters"));
  269. $response->Respond();
  270. }
  271.  
  272. if (strlen($description) > 254)
  273. {
  274. $response->SetError(__("Description can not be longer than 254 characters"));
  275. $response->Respond();
  276. }
  277.  
  278.  
  279. if (strlen($tags) > 254)
  280. {
  281. $response->SetError(__("Tags can not be longer than 254 characters"));
  282. $response->Respond();
  283. }
  284.  
  285. $check = sprintf("SELECT layout FROM layout WHERE layout = '%s' AND userID = %d AND layoutid <> %d ", $db->escape_string($layout), $userid, $this->layoutid);
  286. $result = $db->query($check) or trigger_error($db->error());
  287.  
  288. //Layouts with the same name?
  289. if($db->num_rows($result) != 0)
  290. {
  291. $response->SetError(sprintf(__("You already own a layout called '%s'. Please choose another."), $layout));
  292. $response->Respond();
  293. }
  294. //end validation
  295.  
  296. $SQL = <<<END
  297.  
  298. UPDATE layout SET
  299. layout = '%s',
  300. description = '%s',
  301. modifiedDT = '%s',
  302. retired = %d,
  303. tags = '%s'
  304.  
  305. WHERE layoutID = %s;
  306. END;
  307.  
  308. $SQL = sprintf($SQL,
  309. $db->escape_string($layout),
  310. $db->escape_string($description),
  311. $db->escape_string($currentdate), $retired,
  312. $db->escape_string($tags), $this->layoutid);
  313.  
  314. Debug::LogEntry($db, 'audit', $SQL);
  315.  
  316. if(!$db->query($SQL))
  317. {
  318. trigger_error($db->error());
  319. $response->SetError(sprintf(__("Unknown error editing %s"), $layout));
  320. $response->Respond();
  321. }
  322.  
  323. // Create an array out of the tags
  324. $tagsArray = explode(' ', $tags);
  325.  
  326. // Add the tags XML to the layout
  327. $layoutObject = new Layout($db);
  328.  
  329. // <nb> Calls the EditTags function in layout.data.class.php
  330. if (!$layoutObject->EditTags($this->layoutid, $tagsArray))
  331. {
  332. //there was an ERROR
  333. trigger_error($layoutObject->GetErrorMessage(), E_USER_ERROR);
  334. }
  335.  
  336. // Maintain the name on the campaign
  337. Kit::ClassLoader('campaign');
  338. $campaign = new Campaign($db);
  339. $campaignId = $campaign->GetCampaignId($this->layoutid);
  340. $campaign->Edit($campaignId, $layout);
  341.  
  342. // Notify (dont error)
  343. Kit::ClassLoader('display');
  344. $displayObject = new Display($db);
  345. $displayObject->NotifyDisplays($this->layoutid);
  346.  
  347.  
  348. $response->SetFormSubmitResponse(__('Layout Details Changed.'));
  349. $response->callBack = 'XiboDialogClose';
  350. $response->Respond();
  351. }
  352.  
  353. function delete_form()
  354. {
  355. $db =& $this->db;
  356. $response = new ResponseManager();
  357. $helpManager = new HelpManager($db, $this->user);
  358.  
  359. //expect the $layoutid to be set
  360. $layoutid = $this->layoutid;
  361.  
  362. if (!$this->auth->del)
  363. trigger_error(__('You do not have permissions to delete this layout'), E_USER_ERROR);
  364.  
  365. $defaultLayoutId = config::GetSetting($db, "DEFAULT_LAYOUT");
  366. if ($defaultLayoutId == false) {$defaultLayoutId = 4;}
  367.  
  368. if ($layoutid == $defaultLayoutId)
  369. {
  370. // Can't delete the default Layout
  371. $msgWarn = __('Sorry, this is the Default Layout.');
  372. $msgWarn1 = __('If you wish to delete this Layout,');
  373. $msgWarn2 = __('reallocate DEFAULT_LAYOUT in settings.');
  374.  
  375. $form = <<<END
  376. <form id="LayoutDeleteForm" class="XiboForm" method="post" action="index.php?p=layout&q=nothing">
  377. <input type="hidden" name="layoutid" value="$layoutid">
  378. <p>$msgWarn<br/>
  379. $msgWarn1<br/>
  380. $msgWarn2</p>
  381. </form>
  382. END;
  383.  
  384. }
  385. else
  386. {
  387. // Are we going to be able to delete this?
  388. Kit::ClassLoader('campaign');
  389. $campaign = new Campaign($db);
  390. $campaignId = $campaign->GetCampaignId($layoutid);
  391.  
  392. // Has it been scheduled
  393. $SQL = sprintf("SELECT CampaignID, ToDT FROM schedule WHERE CampaignID = %d AND ToDT > UNIX_TIMESTAMP(NOW()) ORDER BY ToDT DESC;",
  394. $campaignId);
  395.  
  396. if (!$results = $db->query($SQL))
  397. {
  398. trigger_error($db->error());
  399. trigger_error(__("Can not get layout information"), E_USER_ERROR);
  400. }
  401.  
  402. if ($db->num_rows($results) == 0)
  403. {
  404. //we can delete
  405. $msgWarn = __('Are you sure you want to delete this layout? All media will be unassigned. Any layout specific media such as text/rss will be lost.');
  406.  
  407. $form = <<<END
  408. <form id="LayoutDeleteForm" class="XiboForm" method="post" action="index.php?p=layout&q=delete">
  409. <input type="hidden" name="layoutid" value="$layoutid">
  410. <p>$msgWarn</p>
  411. </form>
  412. END;
  413. }
  414. else
  415. {
  416. // Get the first to date on the list
  417. $row = $db->get_row($results) ;
  418. $todt = gmdate("d-m-Y", Kit::ValidateParam($row[1], _STRING));
  419. //we can only retire
  420. $msgWarn = __('Sorry, unable to delete this layout.');
  421. $msgWarn1 = __('Layout is scheduled until '.$todt);
  422. $msgWarn2 = __('Retire this layout instead?');
  423.  
  424. $form = <<<END
  425. <form id="LayoutDeleteForm" class="XiboForm" method="post" action="index.php?p=layout&q=retire">
  426. <input type="hidden" name="layoutid" value="$layoutid">
  427. <p>$msgWarn<br/>
  428. $msgWarn1<br/>
  429. $msgWarn2</p>
  430. </form>
  431. END;
  432. }
  433. }
  434.  
  435. $response->SetFormRequestResponse($form, __('Delete this layout?'), '300px', '235px');
  436. // $response->AddButton(__('Help'), 'XiboHelpRender("' . $helpManager->Link('Layout', 'Delete') . '")');
  437. $response->AddButton(__('No'), 'XiboDialogClose()');
  438. $response->AddButton(__('Yes'), '$("#LayoutDeleteForm").submit()');
  439. $response->Respond();
  440. }
  441.  
  442. /**
  443. * Deletes a layout record from the DB
  444. */
  445. function delete()
  446. {
  447. $db =& $this->db;
  448. $response = new ResponseManager();
  449. $layoutId = Kit::GetParam('layoutid', _POST, _INT, 0);
  450.  
  451. if ($layoutId == 0)
  452. trigger_error(__('No Layout selected'), E_USER_ERROR);
  453.  
  454. $layoutObject = new Layout($db);
  455.  
  456. if (!$layoutObject->Delete($layoutId))
  457. trigger_error($layoutObject->GetErrorMessage(), E_USER_ERROR);
  458.  
  459. $response->SetFormSubmitResponse(__('The Layout has been Deleted'));
  460. $response->callBack = 'XiboDialogClose';
  461. $response->Respond();
  462. }
  463.  
  464. /**
  465. * Retire a Layout
  466. * @return
  467. */
  468. function retire()
  469. {
  470. $db =& $this->db;
  471. $response = new ResponseManager();
  472. $layoutid = Kit::GetParam('layoutid', _POST, _INT, 0);
  473.  
  474. if ($layoutid == 0)
  475. {
  476. $response->SetError(__("No Layout selected"));
  477. $response->Respond();
  478. }
  479.  
  480. $SQL = sprintf("UPDATE layout SET retired = 1 WHERE layoutID = %d", $layoutid);
  481.  
  482.  
  483. if (!$db->query($SQL))
  484. {
  485. trigger_error($db->error());
  486.  
  487. $response->SetError(__("Failed to retire, Unknown Error."));
  488. $response->Respond();
  489. }
  490.  
  491. $response->SetFormSubmitResponse(__('Layout Retired.'));
  492. $response->Respond();
  493. }
  494.  
  495. /**
  496. * Do nothing to the default Layout
  497. * @return
  498. */
  499. function nothing()
  500. {
  501. $db =& $this->db;
  502. $response = new ResponseManager();
  503. $layoutid = Kit::GetParam('layoutid', _POST, _INT, 0);
  504.  
  505. if ($layoutid == 0)
  506. {
  507. $response->SetError(__("No Layout selected"));
  508. $response->Respond();
  509. }
  510.  
  511. $response->SetFormSubmitResponse(__('Layout Unchanged.'));
  512. $response->Respond();
  513. }
  514.  
  515. /**
  516. * Shows the Layout Grid
  517. * @return
  518. */
  519. function LayoutGrid()
  520. {
  521. $db =& $this->db;
  522. $user =& $this->user;
  523. $response = new ResponseManager();
  524.  
  525. $name = Kit::GetParam('filter_layout', _POST, _STRING, '');
  526. setSession('layout', 'filter_layout', $name);
  527.  
  528. // User ID
  529. $filter_userid = Kit::GetParam('filter_userid', _POST, _STRING, 'all');
  530. setSession('layout', 'filter_userid', $filter_userid);
  531.  
  532. // Show retired
  533. $filter_retired = $_REQUEST['filter_retired'];
  534. setSession('layout', 'filter_userid', $filter_userid);
  535.  
  536. // Tags list
  537. $filter_tags = Kit::GetParam("filter_tags", _POST, _STRING);
  538. setSession('layout', 'filter_tags', $filter_tags);
  539.  
  540. $SQL = "";
  541. $SQL .= "SELECT layout.layoutID, ";
  542. $SQL .= " layout.layout, ";
  543. $SQL .= " layout.description, ";
  544. $SQL .= " layout.userID, ";
  545. $SQL .= " campaign.CampaignID ";
  546. // $SQL .= " layout.xml ";
  547. $SQL .= " FROM layout ";
  548. $SQL .= " INNER JOIN `lkcampaignlayout` ";
  549. $SQL .= " ON lkcampaignlayout.LayoutID = layout.LayoutID ";
  550. $SQL .= " INNER JOIN `campaign` ";
  551. $SQL .= " ON lkcampaignlayout.CampaignID = campaign.CampaignID ";
  552. $SQL .= " AND campaign.IsLayoutSpecific = 1";
  553. $SQL .= " WHERE 1= 1";
  554. //name filter
  555. if ($name != "")
  556. {
  557. $SQL.= " AND (layout.layout LIKE '%" . sprintf('%s', $name) . "%') ";
  558. }
  559. //owner filter
  560. if ($filter_userid != "all")
  561. {
  562. $SQL .= sprintf(" AND layout.userid = %d ", $filter_userid);
  563. }
  564. //retired options
  565. if ($filter_retired == "1")
  566. {
  567. $SQL .= " AND layout.retired = 1 ";
  568. }
  569. elseif ($filter_retired == "0")
  570. {
  571. $SQL .= " AND layout.retired = 0 ";
  572. }
  573. if ($filter_tags != "")
  574. {
  575. $SQL .= " AND layout.tags LIKE '%" . sprintf('%s', $filter_tags) . "%' ";
  576. }
  577. error_log($SQL);
  578. error_log("before count time: ".time());
  579. if(!$results = $db->query($SQL))
  580. {
  581. trigger_error($db->error());
  582. trigger_error(__("An Unknown error occured when listing the layouts."), E_USER_ERROR);
  583. }
  584. error_log("after count time: ".time());
  585. //SH $msgCopy = __('Copy');
  586. //SH $msgPermissions = __('Permissions');
  587. //SH $msgDelete = __('Delete');
  588.  
  589. $output = <<<END
  590. <div class="info_table">
  591. <table class="table table-striped" style="width:100%">
  592. <thead>
  593. <tr>
  594. <th class="reduceFont">Name</th>
  595. <th class="reduceFont">Description</th>
  596. <th class="reduceFont">Owner</th>
  597. <th class="reduceFont">$msgPermissions</th>
  598. <th class="reduceFont">Template</th>
  599. <th class="reduceFont">Action</th>
  600.  
  601. </tr>
  602. </thead>
  603. <tbody>
  604. END;
  605. $canvascount = 0;
  606.  
  607. //$resultSet = $db->GetArray($SQL,false);
  608. error_log("before for loop time: ".time());
  609.  
  610. while ($aRow = mysql_fetch_array($results, MYSQL_NUM)) {
  611.  
  612.  
  613. // }
  614. //
  615. //
  616. //
  617. //
  618. // while($aRow = $db->get_row($results))
  619. // {
  620. error_log("in for loop time: ".time());
  621. //get the query results
  622. // $layout = Kit::ValidateParam($aRow[1], _STRING);
  623. // $description = Kit::ValidateParam($aRow[2], _STRING);
  624. // $layoutid = Kit::ValidateParam($aRow[0], _INT);
  625. // $userid = Kit::ValidateParam($aRow[3], _INT);
  626. // $campaignId = Kit::ValidateParam($aRow[4], _INT);
  627. // $xml = base64_encode($aRow[5]);
  628.  
  629. //get the username from the userID using the user module
  630. //SH$username = $user->getNameFromID($userid);
  631. //SH $group = $this->GroupsForLayout($layoutid);
  632. // Permissions
  633. //SH $auth = $this->user->LayoutAuth($layoutid, true);
  634.  
  635. //SH if ($auth->view)
  636. //SH {
  637. //SH if ($auth->edit)
  638. //SH {
  639. // $title = <<<END
  640. // <tr ondblclick="return XiboFormRender('index.php?p=layout&q=displayForm&layoutid=$layoutid')">
  641. // END;
  642. //SH }
  643. //SH else
  644. //SH {
  645. //SH $msgNoPermission = __('You do not have permission to design this layout');
  646. //SH
  647. //SH $title = <<<END
  648. //SH <tr ondblclick="alert('$msgNoPermission')">
  649. //SHEND;
  650. //SH }
  651.  
  652. $output .= <<<END
  653. // $title
  654. // <td>$layout</td>
  655. // <td>$description</td>
  656. // <td>$username</td>
  657. // <td>$group</td>
  658. // <td>
  659. // // <div >
  660. // // <span id="td_$canvascount" style="display:none" class="tocanvas">$xml</span>
  661. // // <canvas id='canvas_td_$canvascount' class="zoomHover" width='70' height='70' style="background-color:rgba(51,51,51,0)"></canvas>
  662. // //
  663. // // <span class="text-content">
  664. // // <span><code>Create Layout</code> with this template</span>
  665. // // </span>
  666. // // </div>
  667. // </td>
  668. END;
  669.  
  670. // $output .= '<td class="nobr" >';
  671. // $output .= '<div class="btn-group"><button class="XiboFormButton btn btn-primary lesspadding" href="index.php?p=schedule&q=ScheduleNowForm&CampaignID=' . $campaignId . '"><span><i class="fa fa-calendar"></i> ' . __('Schedule Now') . '</span></button>';
  672. //
  673. // //SHif ($auth->edit)
  674. // {
  675. // $output .= '<button class="btn btn-success lesspadding" href="index.php?p=layout&modify=true&layoutid=' . $layoutid . '" onclick="window.location = $(this).attr(\'href\')"><span><i class="fa fa-pencil-square-o"></i> Design</span></button>';
  676. // $output .= '<button class="XiboFormButton btn btn-inverse lesspadding" href="index.php?p=layout&q=displayForm&modify=true&layoutid=' . $layoutid . '"><span><i class="glyphicon glyphicon-pencil"></i> Edit</span></button>';
  677. // $output .= '<button onclick="XiboDialogButtonClass()" class="XiboFormButton btn btn-info lesspadding" href="index.php?p=layout&q=CopyForm&layoutid=' . $layoutid . '&oldlayout=' . rawurlencode($layout) . '"><span><i class="fa fa-copy"></i> ' . $msgCopy . '</span></button>';
  678. // //SHif ($auth->del)
  679. // $output .= '<button class="XiboFormButton btn btn-danger lesspadding" href="index.php?p=layout&q=delete_form&layoutid=' . $layoutid . '"><span><i class="fa fa-trash"></i> ' . $msgDelete . '</span></button>';
  680. //
  681. // //SHif ($auth->modifyPermissions)
  682. // $output .= '<button class="XiboFormButton btn btn-warning lesspadding" href="index.php?p=campaign&q=PermissionsForm&CampaignID=' . $campaignId . '"><span><i class="fa fa-lock"></i> ' . $msgPermissions . '</span></button>';
  683. //
  684. // }
  685. //
  686. // $output .= '</div></td>';
  687. $output .= '</tr>';
  688. //SH}
  689. $canvascount++;
  690. }
  691. error_log("after while loop time: ".time());
  692. $output .= '</tbody></table></div>';
  693.  
  694. $response->SetGridResponse($output);
  695. $response->callBack = 'TemplatesRender';
  696. $response->Respond();
  697. }
  698.  
  699. function displayForm ()
  700. {
  701. $db =& $this->db;
  702. $user =& $this->user;
  703. $response = new ResponseManager();
  704. $templateId = Kit::GetParam('templateId', _GET, _STRING, "");
  705. $helpManager = new HelpManager($db, $user);
  706.  
  707. $action = "index.php?p=layout&q=add";
  708.  
  709. $layoutid = $this->layoutid;
  710. $layout = $this->layout;
  711. $description = $this->description;
  712. $retired = $this->retired;
  713. $tags = $this->tags;
  714.  
  715. // Help icons for the form
  716. $nameHelp = $helpManager->HelpIcon(__("The Name of the Layout - (1 - 50 characters)"), true);
  717. $descHelp = $helpManager->HelpIcon(__("An optional description of the Layout. (1 - 250 characters)"), true);
  718. $tagsHelp = $helpManager->HelpIcon(__("Tags for this layout - used when searching for it. Space delimited. (1 - 250 characters)"), true);
  719. $retireHelp = $helpManager->HelpIcon(__("Retire this layout or not? It will no longer be visible in lists"), true);
  720. $templateHelp = $helpManager->HelpIcon(__("Template to create this layout with."), true);
  721.  
  722. //init the retired option
  723. $retired_option = '';
  724. $template_option = '';
  725.  
  726. if ($this->layoutid != '')
  727. {
  728. // assume an edit
  729. $action = "index.php?p=layout&q=modify";
  730.  
  731. // build the retired option
  732. $retired_list = listcontent("1|Yes,0|No","retired",$retired);
  733. $retired_option = <<<END
  734. <tr>
  735. <td><label for='retired'>Retired<span class="required">*</span></label>$retireHelp</td>
  736. <td> $retired_list</td>
  737. </tr>
  738. END;
  739. }
  740. else
  741. {
  742. $templates = $user->TemplateList();
  743. array_unshift($templates, array('templateid' => '0', 'template' => 'None'));
  744.  
  745. $templateList = Kit::SelectList('templateid', $templates, 'templateid', 'template',$templateId);
  746.  
  747. $template_option = <<<END
  748. <tr>
  749. <td><label for='templateid'>Template<span class="required">*</span></label> $templateHelp</td>
  750. <td> $templateList</td>
  751. </tr>
  752. END;
  753. }
  754.  
  755. $msgName = __('Name');
  756. $msgName2 = __('The Name of the Layout - (1 - 50 characters)');
  757. $msgDesc = __('Description');
  758. $msgDesc2 = __('An optional description of the Layout. (1 - 250 characters)');
  759. $msgTags = __('Tags');
  760. $msgTags2 = __('Tags for this layout - used when searching for it. Space delimited. (1 - 250 characters)');
  761.  
  762. $form = <<<END
  763. <form id="LayoutForm" class="XiboForm" method="post" action="$action">
  764. <input class="form-control" type="hidden" name="layoutid" value="$this->layoutid">
  765. <table>
  766. <tr>
  767. <td><label for="layout" accesskey="n" title="$msgName2">$msgName<span class="required">*</span></label>$nameHelp</td>
  768. <td> <input class="form-control" name="layout" type="text" id="layout" value="$layout" tabindex="1" /></td>
  769. </tr>
  770. <tr>
  771. <td><label for="description" accesskey="d" title="$msgDesc2">$msgDesc</label>$descHelp </td>
  772. <td><input class="form-control" name="description" type="text" id="description" value="$description" tabindex="2" /></td>
  773. </tr>
  774. <tr>
  775. <td><label for="tags" accesskey="d" title="$msgTags2">$msgTags</label> $tagsHelp </td>
  776. <td><input class="form-control" name="tags" type="text" id="tags" value="$tags" tabindex="3" /></td>
  777. </tr>
  778. $retired_option
  779. $template_option
  780. </table>
  781. </form>
  782. END;
  783.  
  784. $response->SetFormRequestResponse($form, __('Add/Edit a Layout.'), '380px', '300px'); // Changed from 350 x 275 <nobrolchain@gmail.com 2013-04-16>
  785.  
  786.  
  787.  
  788. // $response->AddButton(__('Help'), 'XiboHelpRender("' . (($this->layoutid != '') ? $helpManager->Link('Layout', 'Edit') : $helpManager->Link('Layout', 'Add')) . '")');
  789. $response->AddButton(__('Cancel'), 'XiboDialogClose()');
  790. $response->AddButton(__('Save'), '$("#LayoutForm").submit()');
  791. $response->Respond();
  792. }
  793.  
  794. /**
  795. * Generates a form for the background edit
  796. * @return
  797. */
  798. function BackgroundForm()
  799. {
  800. $db =& $this->db;
  801. $user =& $this->user;
  802.  
  803. $helpManager = new HelpManager($db, $user);
  804. $response = new ResponseManager();
  805.  
  806.  
  807. //load the XML into a SimpleXML OBJECT
  808. $xml = simplexml_load_string($this->xml);
  809.  
  810. $backgroundImage = (string) $xml['background'];
  811. $backgroundColor = (string) $xml['bgcolor'];
  812. $width = (string) $xml['width'];
  813. $height = (string) $xml['height'];
  814. $bgImageId = 0;
  815.  
  816. // Do we need to override the background with one passed in?
  817. $bgOveride = Kit::GetParam('backgroundOveride', _GET, _STRING);
  818.  
  819. if ($bgOveride != '')
  820. $backgroundImage = $bgOveride;
  821.  
  822. // Manipulate the images slightly
  823. if ($backgroundImage != "")
  824. {
  825. // Get the ID for the background image
  826. $bgImageInfo = explode('.', $backgroundImage);
  827. $bgImageId = $bgImageInfo[0];
  828.  
  829. $thumbBgImage = "index.php?p=module&q=GetImage&id=$bgImageId&width=80&height=80&dynamic";
  830. }
  831. else
  832. {
  833. $thumbBgImage = "img/forms/filenotfound.png";
  834. }
  835.  
  836. // A list of available backgrounds
  837. $backgrounds = $user->MediaList('image');
  838. array_unshift($backgrounds, array('mediaid' => '0', 'media' => 'None'));
  839. $backgroundList = Kit::SelectList('bg_image', $backgrounds, 'mediaid', 'media', $bgImageId, "onchange=\"background_button_callback()\"");
  840.  
  841. //A list of web safe colors
  842. //Strip the # from the currently set color
  843. $backgroundColor = trim($backgroundColor,'#');
  844.  
  845. $webSafeColors = gwsc("bg_color", $backgroundColor);
  846.  
  847. //Get the ID of the current resolution
  848. $SQL = sprintf("SELECT resolutionID FROM resolution WHERE width = %d AND height = %d", $width, $height);
  849.  
  850. if (!$results = $db->query($SQL))
  851. {
  852. trigger_error($db->error());
  853. trigger_error(__("Unable to get the Resolution information"), E_USER_ERROR);
  854. }
  855. $row = $db->get_row($results) ;
  856. $resolutionid = 0;
  857. if ($db->num_rows($results) != 0)
  858. {
  859. $resolutionid = Kit::ValidateParam($row[0], _INT);
  860. }
  861.  
  862. //Make up the list
  863. $SQL = "SELECT resolutionID, resolution, width, height FROM resolution ORDER BY width";
  864. if (!$results = $db->query($SQL))
  865. {
  866. trigger_error($db->error());
  867. trigger_error(__("Unable to get the Resolution information"), E_USER_ERROR);
  868. }
  869. $resolution_list = '<select name="resolutionid" id="resolutionid" class="valid form-control">';
  870. if ($resolutionid == 0) {$resolution_list .= '<option value="0" selected>Custom (' . $width . ' x ' . $height . ')</option>';}
  871. while($row = $db->get_row($results))
  872. {
  873. if ($resolutionid == $row[0]) {$selectRes = " selected";} else {$selectRes = "";}
  874. $resolution_list .= '<option value="' . $row[0] . '"' . $selectRes . '>';
  875. $resolution_list .= $row[1] . ' (' . $row[2] . ' x ' . $row[3] . ')</option>';
  876. }
  877. $resolution_list .= '</select>';
  878.  
  879. // Help text for fields
  880. $resolutionHelp = $helpManager->HelpIcon(__("Pick the resolution"), true);
  881. $bgImageHelp = $helpManager->HelpIcon(__("Select the background image from the library."), true);
  882. $bgColorHelp = $helpManager->HelpIcon(__("Use the color picker to select the background color. To view this, the background image must be set to 'None'."), true);
  883.  
  884. $helpButton = $helpManager->HelpButton("content/layout/layouteditor", true);
  885.  
  886. $msgBg = __('Background Color');
  887. $msgBgTitle = __('Use the color picker to select the background color');
  888. $msgBgImage = __('Background Image');
  889. $msgBgImageTitle = __('Select the background image from the library');
  890. $msgRes = __('Resolution');
  891. $msgResTitle = __('Pick the resolution');
  892.  
  893. // Begin the form output
  894. $form = <<<FORM
  895. <form id="LayoutBackgroundForm" class="XiboForm" method="post" action="index.php?p=layout&q=EditBackground">
  896. <input type="hidden" id="layoutid" name="layoutid" value="$this->layoutid">
  897. <input type="hidden" id="width" name="width" value="$width">
  898. <input type="hidden" id="height" name="height" value="$height">
  899. <table>
  900. <tr>
  901. <td><label for="bg_color" title="$msgBgTitle">$msgBg</label> $bgColorHelp </td>
  902. <td>$webSafeColors</td>
  903. </tr>
  904. <tr>
  905. <td><label for="bg_image" title="$msgBgImageTitle">$msgBgImage</label> $bgImageHelp </td>
  906. <td>$backgroundList</td>
  907. <td rowspan="3"><img id="bg_image_image" src="$thumbBgImage" alt="Thumb" />
  908. </tr>
  909. <tr>
  910. <td><label for="resolutionid" title="$msgResTitle">$msgRes<span class="required">*</span></label> $resolutionHelp </td>
  911. <td>$resolution_list</td>
  912. </tr>
  913. <tr>
  914. <td></td>
  915. </tr>
  916. </table>
  917. </form>
  918. FORM;
  919.  
  920. $response->SetFormRequestResponse($form, __('Change the Background Properties'), '640px', '300px'); // Extended from 550 x 240
  921.  
  922. $response->AddButton(__('Save'), '$("#LayoutBackgroundForm").submit()');
  923. $response->AddButton(__('Cancel'), 'XiboDialogClose()');
  924. $response->AddButton(__('Add Image'), 'XiboDialogButtonClass(); XiboFormRender("index.php?p=module&q=Exec&mod=image&method=AddForm&backgroundImage=true&layoutid=' . $this->layoutid . '")');
  925. // $response->AddButton(__('Help'), 'XiboHelpRender("' . $helpManager->Link('Layout', 'Background') . '")');
  926. $response->Respond();
  927. }
  928.  
  929. /**
  930. * Edits the background of the layout
  931. * @return
  932. */
  933. function EditBackground()
  934. {
  935. $db =& $this->db;
  936. $user =& $this->user;
  937. $response = new ResponseManager();
  938.  
  939. $layoutid = Kit::GetParam('layoutid', _POST, _INT);
  940. $width = Kit::GetParam('width', _POST, _INT);
  941. $height = Kit::GetParam('height', _POST, _INT);
  942. $bg_color = '#'.Kit::GetParam('bg_color', _POST, _STRING);
  943. $mediaID = Kit::GetParam('bg_image', _POST, _INT);
  944. $resolutionid = Kit::GetParam('resolutionid', _POST, _INT);
  945.  
  946. // Get the file URI
  947. $SQL = sprintf("SELECT StoredAs FROM media WHERE MediaID = %d", $mediaID);
  948.  
  949. // Allow for the 0 media idea (no background image)
  950. if ($mediaID == 0)
  951. {
  952. $bg_image = '';
  953. }
  954. else
  955. {
  956. // Look up the bg image from the media id given
  957. if (!$bg_image = $db->GetSingleValue($SQL, 'StoredAs', _STRING))
  958. trigger_error('No media found for that media ID', E_USER_ERROR);
  959. }
  960.  
  961. // Look up the width and the height if a new resolution was selected
  962. if ($resolutionid != 0)
  963. {
  964. $SQL = sprintf("SELECT width, height FROM resolution WHERE resolutionID = %d ", $resolutionid);
  965.  
  966. if (!$results = $db->query($SQL))
  967. {
  968. trigger_error($db->error());
  969. $response->SetError(__("Unable to get the Resolution information"));
  970. $response->Respond();
  971. }
  972.  
  973. $row = $db->get_row($results) ;
  974. $width = Kit::ValidateParam($row[0], _INT);
  975. $height = Kit::ValidateParam($row[1], _INT);
  976. }
  977.  
  978. include_once("lib/pages/region.class.php");
  979.  
  980. $region = new region($db, $user);
  981.  
  982. if (!$region->EditBackground($layoutid, $bg_color, $bg_image, $width, $height))
  983. {
  984. //there was an ERROR
  985. $response->SetError($region->errorMsg);
  986. $response->Respond();
  987. }
  988.  
  989. // Update the layout record with the new background
  990. $SQL = sprintf("UPDATE layout SET background = '%s' WHERE layoutid = %d ", $bg_image, $layoutid);
  991.  
  992. if (!$db->query($SQL))
  993. {
  994. trigger_error($db->error());
  995. $response->SetError(__("Unable to update background information"));
  996. $response->Respond();
  997. }
  998.  
  999. $response->SetFormSubmitResponse(__('Layout Details Changed.'), true, sprintf("index.php?p=layout&layoutid=%d&modify=true", $this->layoutid));
  1000. $response->Respond();
  1001. }
  1002.  
  1003. function GetTransition(){
  1004. error_log("GetTransitionIn");
  1005. $xml = new DOMDocument();
  1006. $xml->loadXML($this->xml);
  1007. error_log("transitionIn:".$xml->documentElement->getAttribute('transitionIn'));
  1008. $response = array();
  1009. $response['transitionIn'] = $xml->documentElement->getAttribute('transitionIn');;
  1010. $response['transitionOut'] = $xml->documentElement->getAttribute('transitionOut');;
  1011. Kit::Redirect($response);
  1012. }
  1013. function UpdateTransitionIn(){
  1014.  
  1015. $db =& $this->db;
  1016. $user =& $this->user;
  1017. $transitionIn = Kit::GetParam('transitionIn', _REQUEST, _STRING);
  1018.  
  1019. $xml = new DOMDocument();
  1020. $xml->loadXML($this->xml);
  1021. error_log("transitionIn:".$xml->documentElement->getAttribute('transitionIn'));
  1022. if($transitionIn=="Empty")
  1023. $xml->documentElement->removeAttribute('transitionIn');
  1024. else
  1025. $xml->documentElement->setAttribute('transitionIn', $transitionIn);
  1026. $saveXML = $xml->saveXML();
  1027. $saveXML = addslashes($saveXML);
  1028. $SQL = sprintf("UPDATE layout SET xml = '%s' WHERE layoutID = %d ", $saveXML, $this->layoutid);
  1029. if (!$db->query($SQL))
  1030. {
  1031. trigger_error("Unable to Update that layouts XML");
  1032. }
  1033. $response = array();
  1034. $response['success'] = true;
  1035. $response['message'] = __('TransitionIn updated');
  1036.  
  1037. Kit::Redirect($response);
  1038.  
  1039. }
  1040.  
  1041. function UpdateTransitionOut(){
  1042.  
  1043. $db =& $this->db;
  1044. $user =& $this->user;
  1045. $transitionOut = Kit::GetParam('transitionOut', _REQUEST, _STRING);
  1046.  
  1047. $xml = new DOMDocument();
  1048. $xml->loadXML($this->xml);
  1049. error_log("transitionOut:".$xml->documentElement->getAttribute('transitionOut'));
  1050. if($transitionOut=="Empty")
  1051. $xml->documentElement->removeAttribute('transitionOut');
  1052. else
  1053. $xml->documentElement->setAttribute('transitionOut', $transitionOut);
  1054. $saveXML = $xml->saveXML();
  1055. $saveXML = addslashes($saveXML);
  1056. $SQL = sprintf("UPDATE layout SET xml = '%s' WHERE layoutID = %d ", $saveXML, $this->layoutid);
  1057. if (!$db->query($SQL))
  1058. {
  1059. trigger_error("Unable to Update that layouts XML");
  1060. }
  1061. $response = array();
  1062. $response['success'] = true;
  1063. $response['message'] = __('TransitionOut updated');
  1064.  
  1065. Kit::Redirect($response);
  1066.  
  1067. }
  1068.  
  1069.  
  1070. /**
  1071. * Sets the default scale type
  1072. * @return
  1073. */
  1074. function UpdateScaleType()
  1075. {
  1076. $db =& $this->db;
  1077. $response = new ResponseManager();
  1078. $scaleType = Kit::GetParam('scaletype', _REQUEST, _STRING);
  1079. $scaleTypeUser = Kit::GetParam('scaletypeuser', _REQUEST, _STRING);
  1080. $currentVal = Config::GetSetting($db, 'scaleType');
  1081. $msgWarn = __('Set (' . $scaleTypeUser . ') as the default scale type?');
  1082. trigger_error($msgWarn);
  1083. // Yes or No
  1084. $form = <<<END
  1085. <form id="ScaleTypeForm" class="XiboForm" method="post" action="index.php?p=layout&q=scaletypeupdate">
  1086. <input type="hidden" name="scaletype" value="$scaleType">
  1087. <table>
  1088. <tr>
  1089. <td>$msgWarn</td>
  1090. </tr>
  1091. </table>
  1092. </form>
  1093. END;
  1094.  
  1095. // Construct the Response
  1096. $response->SetFormRequestResponse($form, __('Set default scale type'), '400', '180');
  1097. $response->AddButton(__('No'), 'XiboDialogClose();$("#scaleType").val("'.$currentVal.'");$("#scaleType").dropdownchecklist("refresh");');
  1098. $response->AddButton(__('Yes'), '$("#ScaleTypeForm").submit()');
  1099. $response->Respond();
  1100.  
  1101. return true;
  1102.  
  1103. }
  1104.  
  1105. function scaletypeupdate()
  1106. {
  1107. $db =& $this->db;
  1108. $scaleType = Kit::GetParam('scaletype', _POST, _STRING);
  1109.  
  1110. $SQL = sprintf("UPDATE setting SET value = '%s' WHERE setting = 'scaleType';", $scaleType);
  1111.  
  1112. if (!$db->query($SQL))
  1113. {
  1114. trigger_error($db->error());
  1115. Kit::Redirect(array('success'=>false, 'message' => __('Scale type was not updated.')));
  1116. }
  1117.  
  1118. // Construct the Response
  1119. $response = array();
  1120. $response['success'] = true;
  1121. $response['message'] = __('Scale Type updated');
  1122.  
  1123. Kit::Redirect($response);
  1124. }
  1125.  
  1126. function UpdateArrows()
  1127. {
  1128. $db =& $this->db;
  1129. $checked = 'Off';
  1130. $checked = Kit::GetParam('checked', _REQUEST, _STRING);
  1131.  
  1132. $SQL = sprintf("UPDATE setting SET value = '%s' WHERE setting = 'SHOW_ARROWS';", $checked);
  1133.  
  1134. if (!$db->query($SQL))
  1135. {
  1136. trigger_error($db->error());
  1137. }
  1138.  
  1139. $response = '';
  1140. Kit::Redirect($response);
  1141. }
  1142.  
  1143. function UpdateTimelines()
  1144. {
  1145. $db =& $this->db;
  1146. $checked = 'Off';
  1147. $checked = Kit::GetParam('checked', _REQUEST, _STRING);
  1148.  
  1149. $SQL = sprintf("UPDATE setting SET value = '%s' WHERE setting = 'SHOW_TIMELINES';", $checked);
  1150.  
  1151. if (!$db->query($SQL))
  1152. {
  1153. trigger_error($db->error());
  1154. }
  1155.  
  1156. $response = '';
  1157. Kit::Redirect($response);
  1158. }
  1159.  
  1160. function UpdateInfo()
  1161. {
  1162. $db =& $this->db;
  1163. $checked = 'Off';
  1164. $checked = Kit::GetParam('checked', _REQUEST, _STRING);
  1165.  
  1166. $SQL = sprintf("UPDATE setting SET value = '%s' WHERE setting = 'SHOW_INFO';", $checked);
  1167.  
  1168. if (!$db->query($SQL))
  1169. {
  1170. trigger_error($db->error());
  1171. }
  1172.  
  1173. $response = '';
  1174. Kit::Redirect($response);
  1175. }
  1176.  
  1177. /**
  1178. * Adds a new region for a layout
  1179. * @return
  1180. */
  1181. function AddRegion()
  1182. {
  1183. $db =& $this->db;
  1184. $user =& $this->user;
  1185.  
  1186. // ajax request handler
  1187. $response = new ResponseManager();
  1188.  
  1189. $layoutid = Kit::GetParam('layoutid', _REQUEST, _INT, 0);
  1190. $top = Kit::GetParam('top', _REQUEST, _INT, 50);
  1191. $left = Kit::GetParam('left', _REQUEST, _INT, 50);
  1192. if ($layoutid == 0)
  1193. {
  1194. trigger_error(__("No layout information available, please refresh the page."), E_USER_ERROR);
  1195. }
  1196.  
  1197. include_once("lib/pages/region.class.php");
  1198.  
  1199. $region = new region($db, $user);
  1200.  
  1201. if (!$region->AddRegion($this->layoutid,'',$top,$left))
  1202. {
  1203. //there was an ERROR
  1204. trigger_error($region->errorMsg, E_USER_ERROR);
  1205. }
  1206.  
  1207. $response->SetFormSubmitResponse(__('Region Added.'), true, "index.php?p=layout&modify=true&layoutid=$layoutid");
  1208. $response->Respond();
  1209. }
  1210.  
  1211. /**
  1212. * Deletes a region and all its media
  1213. * @return
  1214. */
  1215. function DeleteRegion()
  1216. {
  1217. $db =& $this->db;
  1218. $user =& $this->user;
  1219. $response = new ResponseManager();
  1220.  
  1221. $layoutid = Kit::GetParam('layoutid', _REQUEST, _INT, 0);
  1222. $regionid = Kit::GetParam('regionid', _REQUEST, _STRING);
  1223.  
  1224. if ($layoutid == 0 || $regionid == '')
  1225. {
  1226. $response->SetError(__("No layout/region information available, please refresh the page and try again."));
  1227. $response->Respond();
  1228. }
  1229.  
  1230. Kit::ClassLoader('region');
  1231. $region = new region($db, $user);
  1232. $ownerId = $region->GetOwnerId($layoutid, $regionid);
  1233.  
  1234. $regionAuth = $this->user->RegionAssignmentAuth($ownerId, $this->layoutid, $regionid, true);
  1235. if (!$regionAuth->del)
  1236. trigger_error(__('You do not have permissions to delete this region'), E_USER_ERROR);
  1237.  
  1238. // Remove the permissions
  1239. Kit::ClassLoader('layoutregiongroupsecurity');
  1240. $security = new LayoutRegionGroupSecurity($db);
  1241. $security->UnlinkAll($layoutid, $regionid);
  1242.  
  1243. $db->query(sprintf("DELETE FROM lklayoutmediagroup WHERE layoutid = %d AND RegionID = '%s'", $this->layoutid, $regionid));
  1244.  
  1245. if (!$region->DeleteRegion($this->layoutid, $regionid))
  1246. {
  1247. //there was an ERROR
  1248. $response->SetError($region->errorMsg);
  1249. $response->Respond();
  1250. }
  1251.  
  1252. $response->SetFormSubmitResponse(__('Region Deleted.'), true, sprintf("index.php?p=layout&layoutid=%d&modify=true", $this->layoutid));
  1253. $response->Respond();
  1254. }
  1255.  
  1256. /*
  1257. * Form called by the layout which shows a manual positioning/sizing form.
  1258. */
  1259. function ManualRegionPositionForm()
  1260. {
  1261. $db =& $this->db;
  1262. $user =& $this->user;
  1263. $response = new ResponseManager();
  1264.  
  1265. $regionid = Kit::GetParam('regionid', _GET, _STRING);
  1266. $layoutid = Kit::GetParam('layoutid', _GET, _INT);
  1267. $top = Kit::GetParam('top', _GET, _INT);
  1268. $left = Kit::GetParam('left', _GET, _INT);
  1269. $width = Kit::GetParam('width', _GET, _INT);
  1270. $height = Kit::GetParam('height', _GET, _INT);
  1271. $layoutWidth = Kit::GetParam('layoutWidth', _GET, _INT);
  1272. $layoutHeight = Kit::GetParam('layoutHeight', _GET, _INT);
  1273. $layoutHeight = Kit::GetParam('layoutHeight', _GET, _INT);
  1274. $regionPreview = Kit::GetParam('regionPreview', _GET, _INT);
  1275.  
  1276. // If the automatic region preview is selected
  1277. if ($regionPreview == 1)
  1278. {
  1279. $regionHeading = 'Region Information';
  1280.  
  1281. $regionLength = '420px';
  1282. }
  1283. else
  1284. {
  1285. $regionHeading = 'Manual Region Positioning';
  1286. $regionLength = '370px';
  1287. }
  1288.  
  1289. Kit::ClassLoader('region');
  1290. $region = new region($db, $this->user);
  1291. $ownerId = $region->GetOwnerId($layoutid, $regionid);
  1292. $regionName = $region->GetRegionName($layoutid, $regionid);
  1293.  
  1294. $regionAuth = $this->user->RegionAssignmentAuth($ownerId, $this->layoutid, $regionid, true);
  1295. if (!$regionAuth->edit)
  1296. trigger_error(__('You do not have permissions to edit this region'), E_USER_ERROR);
  1297.  
  1298. $form = <<<END
  1299. <form id="RegionProperties" class="XiboForm" method="post" action="index.php?p=layout&q=ManualRegionPosition">
  1300. <input type="hidden" name="layoutid" value="$layoutid">
  1301. <input type="hidden" name="regionid" value="$regionid">
  1302. <input id="layoutWidth" type="hidden" name="layoutWidth" value="$layoutWidth">
  1303. <input id="layoutHeight" type="hidden" name="layoutHeight" value="$layoutHeight">
  1304. <table>
  1305. <tr>
  1306. <td><label for="name" title="Name of the Region">Name</label></td>
  1307. <td><input class="form-control" name="name" type="text" id="name" value="$regionName" tabindex="1" /></td>
  1308. </tr>
  1309. <tr>
  1310. <td><label for="top" title="Offset from the Top Corner">Top Offset</label></td>
  1311. <td><input class="form-control" name="top" type="text" id="top" value="$top" tabindex="2" /></td>
  1312. </tr>
  1313. <tr>
  1314. <td><label for="left" title="Offset from the Left Corner">Left Offset</label></td>
  1315. <td><input class="form-control" name="left" type="text" id="left" value="$left" tabindex="3" /></td>
  1316. </tr>
  1317. <tr>
  1318. <td><label for="width" title="Width of the Region">Width</label></td>
  1319. <td><input class="form-control" name="width" type="text" id="width" value="$width" tabindex="4" /></td>
  1320. </tr>
  1321. <tr>
  1322. <td><label for="height" title="Height of the Region">Height</label></td>
  1323. <td><input class="form-control" name="height" type="text" id="height" value="$height" tabindex="5" /></td>
  1324. </tr>
  1325. <tr>
  1326. <td></td>
  1327. <td>
  1328. <input class="btn btn-primary" id="btnFullScreen" type='button' value="Full Screen" / >
  1329. </td>
  1330. </tr>
  1331. </table>
  1332. </form>
  1333. END;
  1334.  
  1335. $response->SetFormRequestResponse($form, $regionHeading, '350px', $regionLength, 'manualPositionCallback'); // Changed from 350 x 275
  1336. if ($regionPreview == 1)
  1337. {
  1338. $response->AddButton(__('Timeline'),
  1339. 'XiboFormRender("index.php?p=layout&q=Timeline&layoutid=' . $layoutid . '&regionid=' . $regionid . '")');
  1340. $response->AddButton(__('Delete'),
  1341. 'XiboFormRender("index.php?p=layout&q=DeleteRegionForm&layoutid=' . $layoutid . '&regionid=' . $regionid . '")');
  1342. $response->AddButton(__('Permissions'),
  1343. 'XiboFormRender("index.php?p=layout&q=RegionPermissionsForm&layoutid=' . $layoutid . '&regionid=' . $regionid . '")');
  1344. }
  1345.  
  1346. $response->AddButton(__('Save'), '$("#RegionProperties").submit()');
  1347. $response->AddButton(__('Cancel'), 'XiboDialogClose()');
  1348. $response->Respond();
  1349. }
  1350.  
  1351. function ManualRegionPosition()
  1352. {
  1353. $db =& $this->db;
  1354. $user =& $this->user;
  1355. $response = new ResponseManager();
  1356.  
  1357. $layoutid = Kit::GetParam('layoutid', _POST, _INT);
  1358. $regionid = Kit::GetParam('regionid', _POST, _STRING);
  1359. $regionName = Kit::GetParam('name', _POST, _STRING);
  1360. $top = Kit::GetParam('top', _POST, _INT);
  1361. $left = Kit::GetParam('left', _POST, _INT);
  1362. $width = Kit::GetParam('width', _POST, _INT);
  1363. $height = Kit::GetParam('height', _POST, _INT);
  1364.  
  1365. Kit::ClassLoader('region');
  1366. $region = new region($db, $this->user);
  1367. $ownerId = $region->GetOwnerId($layoutid, $regionid);
  1368.  
  1369. $regionAuth = $this->user->RegionAssignmentAuth($ownerId, $this->layoutid, $regionid, true);
  1370. if (!$regionAuth->edit)
  1371. trigger_error(__('You do not have permissions to edit this region'), E_USER_ERROR);
  1372.  
  1373. Debug::LogEntry($db, 'audit', sprintf('Layoutid [%d] Regionid [%s]', $layoutid, $regionid), 'layout', 'ManualRegionPosition');
  1374.  
  1375. // Remove the "px" from them
  1376. $width = str_replace('px', '', $width);
  1377. $height = str_replace('px', '', $height);
  1378. $top = str_replace('px', '', $top);
  1379. $left = str_replace('px', '', $left);
  1380.  
  1381. include_once("lib/pages/region.class.php");
  1382.  
  1383. $region = new region($db, $user);
  1384.  
  1385. if (!$region->EditRegion($layoutid, $regionid, $width, $height, $top, $left, $regionName))
  1386. trigger_error($region->errorMsg, E_USER_ERROR);
  1387.  
  1388. $response->SetFormSubmitResponse('Region Updated', true, "index.php?p=layout&modify=true&layoutid=$layoutid");
  1389. $response->Respond();
  1390. }
  1391.  
  1392. /**
  1393. * Edits the region information
  1394. * @return
  1395. */
  1396. function RegionChange()
  1397. {
  1398. $db =& $this->db;
  1399. $user =& $this->user;
  1400.  
  1401. // ajax request handler
  1402. $response = new ResponseManager();
  1403.  
  1404. //Vars
  1405. $regionid = Kit::GetParam('regionid', _REQUEST, _STRING);
  1406. $name = Kit::GetParam('name', _REQUEST, _STRING);
  1407. $top = Kit::GetParam('top', _POST, _INT);
  1408. $left = Kit::GetParam('left', _POST, _INT);
  1409. $width = Kit::GetParam('width', _POST, _INT);
  1410. $height = Kit::GetParam('height', _POST, _INT);
  1411.  
  1412. // Remove the "px" from them
  1413. $width = str_replace("px", '', $width);
  1414. $height = str_replace("px", '', $height);
  1415. $top = str_replace("px", '', $top);
  1416. $left = str_replace("px", '', $left);
  1417.  
  1418. Kit::ClassLoader('region');
  1419. $region = new region($db, $this->user);
  1420. $ownerId = $region->GetOwnerId($this->layoutid, $regionid);
  1421.  
  1422. //if ($name == '') {$name = NULL;}
  1423.  
  1424. $regionAuth = $this->user->RegionAssignmentAuth($ownerId, $this->layoutid, $regionid, true);
  1425. if (!$regionAuth->del)
  1426. trigger_error(__('You do not have permissions to edit this region'), E_USER_ERROR);
  1427.  
  1428. if (!$region->EditRegion($this->layoutid, $regionid, $width, $height, $top, $left, $name))
  1429. {
  1430. //there was an ERROR
  1431. trigger_error($region->errorMsg, E_USER_ERROR);
  1432. }
  1433.  
  1434. $response->SetFormSubmitResponse('');
  1435. $response->hideMessage = true;
  1436. $response->Respond();
  1437. }
  1438.  
  1439. /**
  1440. * Return the Delete Form as HTML
  1441. * @return
  1442. */
  1443. public function DeleteRegionForm()
  1444. {
  1445. $db =& $this->db;
  1446. $response = new ResponseManager();
  1447. $helpManager = new HelpManager($db, $this->user);
  1448. $layoutid = Kit::GetParam('layoutid', _REQUEST, _INT, 0);
  1449. $regionid = Kit::GetParam('regionid', _REQUEST, _STRING);
  1450.  
  1451. Kit::ClassLoader('region');
  1452. $region = new region($db, $this->user);
  1453. $ownerId = $region->GetOwnerId($layoutid, $regionid);
  1454.  
  1455. $regionAuth = $this->user->RegionAssignmentAuth($ownerId, $this->layoutid, $regionid, true);
  1456. if (!$regionAuth->del)
  1457. trigger_error(__('You do not have permissions to delete this region'), E_USER_ERROR);
  1458.  
  1459. // Translate messages
  1460. $msgDelete = __('Are you sure you want to remove this region?');
  1461. $msgDelete2 = __('All media files will be unassigned and any context saved to the region itself (such as Text, Tickers) will be lost permanently.');
  1462. $msgYes = __('Yes');
  1463. $msgNo = __('No');
  1464.  
  1465. //we can delete
  1466. $form = <<<END
  1467. <form id="RegionDeleteForm" class="XiboForm" method="post" action="index.php?p=layout&q=DeleteRegion">
  1468. <input type="hidden" name="layoutid" value="$layoutid">
  1469. <input type="hidden" name="regionid" value="$regionid">
  1470. <p>$msgDelete $msgDelete2</p>
  1471. </form>
  1472. END;
  1473.  
  1474. $response->SetFormRequestResponse($form, __('Delete this region?'), '350px', '250px'); // Extended from 350 x 200
  1475. $response->AddButton(__('Delete'), '$("#RegionDeleteForm").submit()');
  1476. $response->AddButton(__('Cancel'), 'XiboDialogClose()');
  1477. // $response->AddButton(__('Help'), 'XiboHelpRender("' . $helpManager->Link('Region', 'Delete') . '")');
  1478. $response->Respond();
  1479. }
  1480.  
  1481. function RenderDesigner()
  1482. {
  1483. $db =& $this->db;
  1484. $user =& $this->user;
  1485.  
  1486. // Assume we have the xml in memory already
  1487. // Make a DOM from the XML
  1488. $xml = new DOMDocument();
  1489. $xml->loadXML($this->xml);
  1490.  
  1491. // get the width and the height
  1492. $width = $xml->documentElement->getAttribute('width');
  1493. $height = $xml->documentElement->getAttribute('height');
  1494.  
  1495. //do we have a background? Or a background color (or both)
  1496. $bgImage = $xml->documentElement->getAttribute('background');
  1497. $bgColor = $xml->documentElement->getAttribute('bgcolor');
  1498.  
  1499. //Library location
  1500. $libraryLocation = Config::GetSetting($db, "LIBRARY_LOCATION");
  1501.  
  1502. //Fix up the background css
  1503. if ($bgImage == '')
  1504. {
  1505. $background_css = $bgColor;
  1506. }
  1507. else
  1508. {
  1509. // Get the ID for the background image
  1510. $bgImageInfo = explode('.', $bgImage);
  1511. $bgImageId = $bgImageInfo[0];
  1512.  
  1513. $background_css = "url('index.php?p=module&q=GetImage&id=$bgImageId&width=$width&height=$height&dynamic&proportional=0') top center no-repeat; background-color:$bgColor";
  1514. }
  1515.  
  1516. $width = $width . "px";
  1517. $height = $height . "px";
  1518.  
  1519. // Get all the regions and draw them on
  1520. $regionHtml = "";
  1521. $regionNodeList = $xml->getElementsByTagName('region');
  1522. $counter = 0;
  1523.  
  1524. //get the regions
  1525. foreach ($regionNodeList as $region)
  1526. {
  1527.  
  1528. // get dimensions
  1529. $tipWidth = $region->getAttribute('width');
  1530. $tipHeight = $region->getAttribute('height');
  1531. $tipTop = $region->getAttribute('top');
  1532. $tipLeft = $region->getAttribute('left');
  1533.  
  1534. $regionWidth = $region->getAttribute('width') . "px";
  1535. $regionHeight = $region->getAttribute('height') . "px";
  1536. $regionLeft = $region->getAttribute('left') . "px";
  1537. $regionTop = $region->getAttribute('top') . "px";
  1538. $regionid = $region->getAttribute('id');
  1539. $regionname = $region->getAttribute('name');
  1540. $ownerId = $region->getAttribute('userId');
  1541.  
  1542. $regionAuth = $this->user->RegionAssignmentAuth($ownerId, $this->layoutid, $regionid, true);
  1543.  
  1544. $paddingTop = $regionHeight / 2 - 16;
  1545. $paddingTop = $paddingTop . "px";
  1546.  
  1547. $regionAuthTransparency = ($regionAuth->edit) ? '' : ' regionDisabled';
  1548. $regionDisabledClass = ($regionAuth->edit) ? 'region' : 'regionDis';
  1549. $regionPreviewClass = ($regionAuth->view) ? 'regionPreview' : '';
  1550.  
  1551. $regionTransparency = '<div class="regionTransparency ' . $regionAuthTransparency . '" style="width:100%; height:100%;"></div>';
  1552. $doubleClickLink = ($regionAuth->edit) ? "XiboFormRender($(this).attr('href'))" : '';
  1553.  
  1554. $regionHtml .= "<div id='region_$regionid' regionEnabled='$regionAuth->edit' regionid='$regionid' counter='$counter' regionname='$regionname' layoutid='$this->layoutid' href='index.php?p=layout&layoutid=$this->layoutid&regionid=$regionid&q=RegionOptions' ondblclick=\"$doubleClickLink\"' class='$regionDisabledClass $regionPreviewClass' style=\"position:absolute; width:$regionWidth; height:$regionHeight; top: $regionTop; left: $regionLeft;\">
  1555. $regionTransparency";
  1556.  
  1557. if ($regionAuth->view)
  1558. {
  1559. $regionHtml .= "<div id='regionInfo_" . $regionid . "' class='regionInfo' style='display:none;'>
  1560. $tipWidth x $tipHeight ($tipLeft,$tipTop)
  1561. </div>
  1562. <div class='preview'>
  1563. <div class='previewContent'></div>
  1564. <div id='previewNav_" . $regionid . "' class='previewNav'></div>
  1565. </div>";
  1566. }
  1567.  
  1568. if ($regionAuth->edit)
  1569. {
  1570. $regionHtml .= "<div id='timelineLink_" . $regionid . "' class='timelineLink' style='display:none;'>";
  1571. $regionHtml .= ' <a class="XiboFormButton" href="index.php?p=layout&q=Timeline&layoutid=' . $this->layoutid . '&regionid=' . $regionid . '" title="' . __('Timeline') . '">' . __('Edit Timeline') . '</a>';
  1572. $regionHtml .= '</div>';
  1573. }
  1574.  
  1575. $regionHtml .= '</div>';
  1576. $counter = $counter + 1;
  1577. }
  1578.  
  1579. // Set up dummy region if there are no regions
  1580. if ($regionHtml == '') {
  1581. $regionAuth = $this->user->RegionAssignmentAuth($user, $this->layoutid, 0, true);
  1582. $regionHtml .= "<div id='region_dummy' regionEnabled='$regionAuth->edit' regionid='0' counter='0'
  1583. regionname='dummy' layoutid='$this->layoutid' class='region' style=\"display:none;\">";
  1584. }
  1585.  
  1586. // Translate messages
  1587. $msgTimeLine = __('Timeline');
  1588. $msgOptions = __('Options');
  1589. $msgDelete = __('Delete');
  1590. $msgSetAsHome = __('Permissions');
  1591.  
  1592. $msgAddRegion = __('Add Region');
  1593. $msgEditBg = __('Edit Background');
  1594. $msgProperties = __('Properties');
  1595. $msgSaveTemplate = __('Save Template');
  1596.  
  1597.  
  1598. /*<!--<div id="aspectRatioOption">
  1599. <input id="lockAspectRatio" type="checkbox" /><label for="lockAspectRatio">Lock Aspect Ratio?</label>
  1600. </div>-->*/
  1601.  
  1602. //render the view pane
  1603. $surface = <<<HTML
  1604. <div id="layout" layoutid="$this->layoutid" style="position:relative; width:$width; height:$height; background:$background_css;">
  1605. $regionHtml
  1606. </div>
  1607. <div class="contextMenu" id="regionMenu">
  1608. <ul>
  1609. <li style="z-index:10002" id="btnTimeline">$msgTimeLine</li>
  1610. <li style="z-index:10002" id="options">$msgOptions</li>
  1611. <li style="z-index:10002" id="deleteRegion">$msgDelete</li>
  1612. <li style="z-index:10002" id="setAsHomepage">$msgSetAsHome</li>
  1613. </ul>
  1614. </div>
  1615. <div class="contextMenu" id="layoutMenu">
  1616. <ul>
  1617. <li id="addRegion">$msgAddRegion</li>
  1618. <li id="editBackground">$msgEditBg</li>
  1619. <li id="layoutProperties">$msgProperties</li>
  1620. <li id="templateSave">$msgSaveTemplate</li>
  1621. </ul>
  1622. </div>
  1623. HTML;
  1624.  
  1625. echo $surface;
  1626.  
  1627. return true;
  1628. }
  1629.  
  1630. /**
  1631. * Shows the Timeline for this region
  1632. * Also shows any Add/Edit options
  1633. * @return
  1634. */
  1635. function RegionOptions()
  1636. {
  1637. $this->Timeline();
  1638. exit();
  1639. }
  1640.  
  1641. /**
  1642. * Adds the media into the region provided
  1643. * @return
  1644. */
  1645. function AddFromLibrary()
  1646. {
  1647. $db =& $this->db;
  1648. $user =& $this->user;
  1649. $response = new ResponseManager();
  1650.  
  1651. $layoutId = Kit::GetParam('layoutid', _GET, _INT);
  1652. $regionId = Kit::GetParam('regionid', _POST, _STRING);
  1653. $mediaList = Kit::GetParam('MediaID', _POST, _ARRAY, array());
  1654.  
  1655. // Make sure we have permission to edit this region
  1656. Kit::ClassLoader('region');
  1657. $region = new region($db, $user);
  1658. $ownerId = $region->GetOwnerId($layoutId, $regionId);
  1659.  
  1660. $regionAuth = $this->user->RegionAssignmentAuth($ownerId, $layoutId, $regionId, true);
  1661. if (!$regionAuth->edit)
  1662. trigger_error(__('You do not have permissions to edit this region'), E_USER_ERROR);
  1663.  
  1664. // Check that some media assignments have been made
  1665. if (count($mediaList) == 0)
  1666. trigger_error(__('No media to assign'), E_USER_ERROR);
  1667.  
  1668. // Loop through all the media
  1669. foreach ($mediaList as $mediaId)
  1670. {
  1671. $mediaId = Kit::ValidateParam($mediaId, _INT);
  1672.  
  1673. // Check we have permissions to use this media (we will use this to copy the media later)
  1674. $mediaAuth = $this->user->MediaAuth($mediaId, true);
  1675.  
  1676. if (!$mediaAuth->view)
  1677. {
  1678. $response->SetError(__('You have selected media that you no longer have permission to use. Please reload Library form.'));
  1679. $response->keepOpen = true;
  1680. return $response;
  1681. }
  1682.  
  1683. // Get the type from this media
  1684. $SQL = sprintf("SELECT type FROM media WHERE mediaID = %d", $mediaId);
  1685.  
  1686. if (!$mod = $db->GetSingleValue($SQL, 'type', _STRING))
  1687. {
  1688. trigger_error($db->error());
  1689. $response->SetError(__('Error getting type from a media item.'));
  1690. $response->keepOpen = false;
  1691. return $response;
  1692. }
  1693.  
  1694. require_once("modules/$mod.module.php");
  1695.  
  1696. // Create the media object without any region and layout information
  1697. $this->module = new $mod($db, $user, $mediaId);
  1698.  
  1699. if ($this->module->SetRegionInformation($layoutId, $regionId))
  1700. $this->module->UpdateRegion();
  1701. else
  1702. {
  1703. $response->SetError(__('Cannot set region information.'));
  1704. $response->keepOpen = true;
  1705. return $response;
  1706. }
  1707.  
  1708. // Need to copy over the permissions from this media item & also the delete permission
  1709. Kit::ClassLoader('layoutmediagroupsecurity');
  1710. $security = new LayoutMediaGroupSecurity($db);
  1711. $security->Link($layoutId, $regionId, $mediaId, $this->user->getGroupFromID($this->user->userid, true), $mediaAuth->view, $mediaAuth->edit, 1);
  1712. }
  1713.  
  1714. // We want to load a new form
  1715. $response->SetFormSubmitResponse(sprintf(__('%d Media Items Assigned'), count($mediaList)));
  1716. $response->loadForm = true;
  1717. $response->loadFormUri = "index.php?p=layout&layoutid=$layoutId&regionid=$regionId&q=RegionOptions";
  1718. $response->Respond();
  1719. }
  1720.  
  1721. /**
  1722. * Properties Edit
  1723. * @return
  1724. */
  1725. function EditPropertiesHref()
  1726. {
  1727. //output the button
  1728. echo "index.php?p=layout&q=displayForm&modify=true&layoutid=$this->layoutid";
  1729. }
  1730.  
  1731. function EditBackgroundHref()
  1732. {
  1733. //output the button
  1734. echo "index.php?p=layout&q=BackgroundForm&modify=true&layoutid=$this->layoutid";
  1735. }
  1736.  
  1737. function ScheduleNowHref()
  1738. {
  1739. // Get the Campaign ID
  1740. $SQL = "SELECT campaign.CampaignID ";
  1741. $SQL .= " FROM `lkcampaignlayout` ";
  1742. $SQL .= " INNER JOIN `campaign` ";
  1743. $SQL .= " ON lkcampaignlayout.CampaignID = campaign.CampaignID ";
  1744. $SQL .= " WHERE lkcampaignlayout.LayoutID = %d ";
  1745. $SQL .= " AND campaign.IsLayoutSpecific = 1";
  1746.  
  1747. if (!$campaignId = $this->db->GetSingleValue(sprintf($SQL, $this->layoutid), 'CampaignID', _INT))
  1748. trigger_error(__('Layout has no associated Campaign, corrupted Layout'), E_USER_ERROR);
  1749.  
  1750.  
  1751. echo 'index.php?p=schedule&q=ScheduleNowForm&CampaignID=' . $campaignId;
  1752. }
  1753.  
  1754. /**
  1755. * Called by AJAX
  1756. * @return
  1757. */
  1758. public function RegionPreview()
  1759. {
  1760. $db =& $this->db;
  1761. $user =& $this->user;
  1762.  
  1763. include_once("lib/pages/region.class.php");
  1764.  
  1765. //ajax request handler
  1766. $response = new ResponseManager();
  1767.  
  1768. //Expect
  1769. $layoutid = Kit::GetParam('layoutid', _POST, _INT, 0);
  1770. $regionid = Kit::GetParam('regionid', _POST, _STRING);
  1771.  
  1772. $seqGiven = Kit::GetParam('seq', _POST, _INT, 0);
  1773. $seq = Kit::GetParam('seq', _POST, _INT, 0);
  1774. $width = Kit::GetParam('width', _POST, _INT, 0);
  1775. $height = Kit::GetParam('height', _POST, _INT, 0);
  1776.  
  1777. // The sequence will not be zero based, so adjust it
  1778. $seq--;
  1779.  
  1780. // Get some region imformation
  1781. $return = "";
  1782. $xml = new DOMDocument("1.0");
  1783. $region = new region($db, $user);
  1784.  
  1785. if (!$xmlString = $region->GetLayoutXml($layoutid))
  1786. {
  1787. trigger_error($region->errorMsg, E_USER_ERROR);
  1788. }
  1789.  
  1790. $xml->loadXML($xmlString);
  1791.  
  1792. // This will be all the media nodes in the region provided
  1793. $xpath = new DOMXPath($xml);
  1794. $nodeList = $xpath->query("//region[@id='$regionid']/media");
  1795.  
  1796. $return = "<input type='hidden' id='maxSeq' value='{$nodeList->length}' />";
  1797. $return .= "<div id='seqInfo_" . $regionid . "' class='seqInfo' style='position:absolute; right:15px; top:31px; color:#FFF; background-color:#000; z-index:50; padding: 5px; display:none;'>
  1798. <span style='font-family: Verdana;'>$seqGiven / {$nodeList->length}</span>
  1799. </div>";
  1800. $return .= '<div class="regionPreviewOverlay"></div>';
  1801.  
  1802. if ($nodeList->length == 0)
  1803. {
  1804. // No media to preview
  1805. $return .= "<h1>" . "</h1>";
  1806.  
  1807. $response->html = $return;
  1808. $response->Respond();
  1809. }
  1810.  
  1811. $node = $nodeList->item($seq);
  1812.  
  1813. // We have our node.
  1814. $type = (string) $node->getAttribute("type");
  1815. $mediaDurationText = (string) $node->getAttribute("duration");
  1816. $mediaid = (string) $node->getAttribute("id");
  1817.  
  1818. $return .= "
  1819. <div id='previewInfo_" . $regionid . "' class='previewInfo' style='position:absolute; right:15px; top:61px; color:#FFF; background-color:#000; z-index:50; padding: 5px; font-family: Verdana; display:none;'>
  1820. <span style='font-family: Verdana;'>Type: $type <br />
  1821. Duration: $mediaDurationText (s)</span>
  1822. </div>";
  1823.  
  1824. // Create a module to deal with this
  1825. if (!file_exists('modules/' . $type . '.module.php'))
  1826. {
  1827. $return .= 'Unknow module type';
  1828. }
  1829.  
  1830. require_once("modules/$type.module.php");
  1831.  
  1832. $moduleObject = new $type($db, $user, $mediaid, $layoutid, $regionid);
  1833.  
  1834. $return .= $moduleObject->Preview($width, $height);
  1835.  
  1836. $response->html = $return;
  1837. $response->Respond();
  1838. }
  1839.  
  1840. /**
  1841. * Copy layout form
  1842. */
  1843. public function CopyForm()
  1844. {
  1845. $db =& $this->db;
  1846. $user =& $this->user;
  1847. $response = new ResponseManager();
  1848.  
  1849. $helpManager = new HelpManager($db, $user);
  1850.  
  1851. $layoutid = Kit::GetParam('layoutid', _REQUEST, _INT);
  1852. $oldLayout = Kit::GetParam('oldlayout', _REQUEST, _STRING);
  1853. $userid = Kit::GetParam('userid', _SESSION, _INT);
  1854.  
  1855. $msgName = __('New Name');
  1856. $msgName2 = __('The name for the new layout');
  1857. $msgCopyMedia = __('Make new copies of all media on this layout?');
  1858.  
  1859. $sql = " SELECT userid, userName FROM user";
  1860.  
  1861. if(!$results = $db->query($sql))
  1862. {
  1863. trigger_error($db->error());
  1864. trigger_error(__("Cannot retrieve user list "), E_USER_ERROR);
  1865. }
  1866. $user_options ='';
  1867. while($aRow = $db->get_row($results))
  1868. {
  1869. $userId = Kit::ValidateParam($aRow[0], _STRING);
  1870. $userName = Kit::ValidateParam($aRow[1], _STRING);
  1871. error_log("User:".$userId.":".$userName);
  1872. if($userid == $userId)
  1873. $user_options .= "<option value='".$userId."' selected>".$userName."</option>";
  1874. else
  1875. $user_options .= "<option value='".$userId."'>".$userName."</option>";
  1876. }
  1877.  
  1878.  
  1879. $copyMediaChecked = (Config::GetSetting($db, 'LAYOUT_COPY_MEDIA_CHECKB') == 'Checked') ? 'checked' : '';
  1880.  
  1881. $form = <<<END
  1882. <form id="LayoutCopyForm" class="XiboForm" method="post" action="index.php?p=layout&q=Copy">
  1883. <input type="hidden" name="layoutid" value="$layoutid">
  1884. <table>
  1885. <tr>
  1886. <td><label for="layout" accesskey="n" title="$msgName2">$msgName<span class="required">*</span></label></td>
  1887. <td><input name="layout" class="required form-control" type="text" id="layout" value="$oldLayout 2" tabindex="1" /></td>
  1888. </tr>
  1889. <tr>
  1890. <td><label for="select_user" accesskey="u" title="Copy As User">Copy As User<span class="required">*</span></label></td>
  1891. <td><select class="form-control" name="select_user" id="select_user">$user_options</select></td>
  1892.  
  1893. </td>
  1894. </tr>
  1895. <tr>
  1896. <td colspan="2">
  1897. <input type="checkbox" id="copyMediaFiles" name="copyMediaFiles" $copyMediaChecked />
  1898. <label for="copyMediaFiles" accesskey="c" title="$msgCopyMedia">$msgCopyMedia</label>
  1899. </td>
  1900. </tr>
  1901. </table>
  1902. </form>
  1903. END;
  1904.  
  1905. $response->SetFormRequestResponse($form, __('Copy a Layout.'), '350px', '275px');
  1906. // $response->AddButton(__('Help'), 'XiboHelpRender("' . $helpManager->Link('Layout', 'Copy') . '")');
  1907. $response->AddButton(__('Cancel'), 'XiboDialogClose()');
  1908. $response->AddButton(__('Copy'), '$("#LayoutCopyForm").submit()');
  1909. $response->Respond();
  1910. }
  1911.  
  1912. /**
  1913. * Copys a layout
  1914. */
  1915. public function Copy()
  1916. {
  1917. $db =& $this->db;
  1918. $user =& $this->user;
  1919. $response = new ResponseManager();
  1920.  
  1921. $layoutid = Kit::GetParam('layoutid', _POST, _INT);
  1922. $layout = Kit::GetParam('layout', _POST, _STRING);
  1923. $copyMedia = Kit::GetParam('copyMediaFiles', _POST, _CHECKBOX);
  1924. $select_user = Kit::GetParam('select_user', _POST, _INT);
  1925. Kit::ClassLoader('Layout');
  1926.  
  1927. $layoutObject = new Layout($db);
  1928.  
  1929. if (!$layoutObject->Copy($layoutid, $layout, $select_user, (bool)$copyMedia))
  1930. trigger_error($layoutObject->GetErrorMessage(), E_USER_ERROR);
  1931.  
  1932. $response->SetFormSubmitResponse(__('Layout Copied'));
  1933. $response->callBack = 'XiboDialogClose';
  1934. $response->Respond();
  1935. }
  1936.  
  1937. public function RegionPermissionsForm()
  1938. {
  1939. $db =& $this->db;
  1940. $user =& $this->user;
  1941. $response = new ResponseManager();
  1942. $helpManager = new HelpManager($db, $user);
  1943.  
  1944. $layoutid = Kit::GetParam('layoutid', _GET, _INT);
  1945. $regionid = Kit::GetParam('regionid', _GET, _STRING);
  1946.  
  1947. Kit::ClassLoader('region');
  1948. $region = new region($db, $user);
  1949. $ownerId = $region->GetOwnerId($layoutid, $regionid);
  1950.  
  1951. $regionAuth = $this->user->RegionAssignmentAuth($ownerId, $this->layoutid, $regionid, true);
  1952. if (!$regionAuth->modifyPermissions)
  1953. trigger_error(__("You do not have permissions to edit this regions permissions"), E_USER_ERROR);
  1954.  
  1955. // Form content
  1956. $form = '<form id="RegionPermissionsForm" class="XiboForm" method="post" action="index.php?p=layout&q=RegionPermissions">';
  1957. $form .= '<input type="hidden" name="layoutid" value="' . $layoutid . '" />';
  1958. $form .= '<input type="hidden" name="regionid" value="' . $regionid . '" />';
  1959. $form .= '<div >';
  1960. $form .= ' <table class="table table-striped">';
  1961. $form .= ' <tr>';
  1962. $form .= ' <th>' . __('Group') . '</th>';
  1963. $form .= ' <th>' . __('View') . '</th>';
  1964. $form .= ' <th>' . __('Edit') . '</th>';
  1965. $form .= ' <th>' . __('Delete') . '</th>';
  1966. $form .= ' </tr>';
  1967.  
  1968. // List of all Groups with a view/edit/delete checkbox
  1969. $SQL = '';
  1970. $SQL .= 'SELECT `group`.GroupID, `group`.`Group`, View, Edit, Del, `group`.IsUserSpecific ';
  1971. $SQL .= ' FROM `group` ';
  1972. $SQL .= ' LEFT OUTER JOIN lklayoutregiongroup ';
  1973. $SQL .= ' ON lklayoutregiongroup.GroupID = group.GroupID ';
  1974. $SQL .= ' AND lklayoutregiongroup.LayoutID = %d ';
  1975. $SQL .= " AND lklayoutregiongroup.RegionID = '%s' ";
  1976. $SQL .= ' WHERE `group`.GroupID <> %d ';
  1977. $SQL .= 'ORDER BY `group`.IsEveryone DESC, `group`.IsUserSpecific, `group`.`Group` ';
  1978.  
  1979. $SQL = sprintf($SQL, $layoutid, $regionid, $user->getGroupFromId($user->userid, true));
  1980.  
  1981. if (!$results = $db->query($SQL))
  1982. {
  1983. trigger_error($db->error());
  1984. trigger_error(__('Unable to get permissions for this layout region'), E_USER_ERROR);
  1985. }
  1986.  
  1987. while($row = $db->get_assoc_row($results))
  1988. {
  1989. $groupId = $row['GroupID'];
  1990. $group = ($row['IsUserSpecific'] == 0) ? '<strong>' . $row['Group'] . '</strong>' : $row['Group'];
  1991.  
  1992. $form .= '<tr>';
  1993. $form .= ' <td>' . $group . '</td>';
  1994. $form .= ' <td><input type="checkbox" name="groupids[]" value="' . $groupId . '_view" ' . (($row['View'] == 1) ? 'checked' : '') . '></td>';
  1995. $form .= ' <td><input type="checkbox" name="groupids[]" value="' . $groupId . '_edit" ' . (($row['Edit'] == 1) ? 'checked' : '') . '></td>';
  1996. $form .= ' <td><input type="checkbox" name="groupids[]" value="' . $groupId . '_del" ' . (($row['Del'] == 1) ? 'checked' : '') . '></td>';
  1997. $form .= '</tr>';
  1998. }
  1999.  
  2000. $form .= '</table>';
  2001. $form .= '</div>';
  2002. $form .= '</form>';
  2003.  
  2004. $response->SetFormRequestResponse($form, __('Permissions'), '350px', '500px');
  2005.  
  2006. $response->AddButton(__('Save'), '$("#RegionPermissionsForm").submit()');
  2007. $response->AddButton(__('Cancel'), 'XiboDialogClose()');
  2008. // $response->AddButton(__('Help'), 'XiboHelpRender("' . $helpManager->Link('Region', 'Permissions') . '")');
  2009. $response->Respond();
  2010. }
  2011.  
  2012. public function RegionPermissions()
  2013. {
  2014. $db =& $this->db;
  2015. $user =& $this->user;
  2016. $response = new ResponseManager();
  2017. Kit::ClassLoader('layoutregiongroupsecurity');
  2018.  
  2019. $layoutId = Kit::GetParam('layoutid', _POST, _INT);
  2020. $regionId = Kit::GetParam('regionid', _POST, _STRING);
  2021. $groupIds = Kit::GetParam('groupids', _POST, _ARRAY);
  2022.  
  2023. Kit::ClassLoader('region');
  2024. $region = new region($db, $user);
  2025. $ownerId = $region->GetOwnerId($layoutId, $regionId);
  2026.  
  2027. $regionAuth = $this->user->RegionAssignmentAuth($ownerId, $this->layoutid, $regionId, true);
  2028. if (!$regionAuth->modifyPermissions)
  2029. trigger_error(__('You do not have permissions to edit this regions permissions'), E_USER_ERROR);
  2030.  
  2031. // Unlink all
  2032. $layoutSecurity = new LayoutRegionGroupSecurity($db);
  2033. if (!$layoutSecurity->UnlinkAll($layoutId, $regionId))
  2034. trigger_error(__('Unable to set permissions'));
  2035.  
  2036. // Some assignments for the loop
  2037. $lastGroupId = 0;
  2038. $first = true;
  2039. $view = 0;
  2040. $edit = 0;
  2041. $del = 0;
  2042.  
  2043. // List of groupIds with view, edit and del assignments
  2044. foreach($groupIds as $groupPermission)
  2045. {
  2046. $groupPermission = explode('_', $groupPermission);
  2047. $groupId = $groupPermission[0];
  2048.  
  2049. if ($first)
  2050. {
  2051. // First time through
  2052. $first = false;
  2053. $lastGroupId = $groupId;
  2054. }
  2055.  
  2056. if ($groupId != $lastGroupId)
  2057. {
  2058. // The groupId has changed, so we need to write the current settings to the db.
  2059. // Link new permissions
  2060. if (!$layoutSecurity->Link($layoutId, $regionId, $lastGroupId, $view, $edit, $del))
  2061. trigger_error(__('Unable to set permissions'));
  2062.  
  2063. // Reset
  2064. $lastGroupId = $groupId;
  2065. $view = 0;
  2066. $edit = 0;
  2067. $del = 0;
  2068. }
  2069.  
  2070. switch ($groupPermission[1])
  2071. {
  2072. case 'view':
  2073. $view = 1;
  2074. break;
  2075.  
  2076. case 'edit':
  2077. $edit = 1;
  2078. break;
  2079.  
  2080. case 'del':
  2081. $del = 1;
  2082. break;
  2083. }
  2084. }
  2085.  
  2086. // Need to do the last one
  2087. if (!$first)
  2088. {
  2089. if (!$layoutSecurity->Link($layoutId, $regionId, $lastGroupId, $view, $edit, $del))
  2090. trigger_error(__('Unable to set permissions'));
  2091. }
  2092.  
  2093. $response->SetFormSubmitResponse(__('Permissions Changed'));
  2094. $response->Respond();
  2095. }
  2096.  
  2097. /**
  2098. * Get a list of group names for a layout
  2099. * @param <type> $layoutId
  2100. * @return <type>
  2101. */
  2102. private function GroupsForLayout($layoutId)
  2103. {
  2104. $db =& $this->db;
  2105.  
  2106. Kit::ClassLoader('campaign');
  2107. $campaign = new Campaign($db);
  2108. $campaignId = $campaign->GetCampaignId($layoutId);
  2109.  
  2110. $SQL = '';
  2111. $SQL .= 'SELECT `group`.Group ';
  2112. $SQL .= ' FROM `group` ';
  2113. $SQL .= ' INNER JOIN lkcampaigngroup ';
  2114. $SQL .= ' ON `group`.GroupID = lkcampaigngroup.GroupID ';
  2115. $SQL .= ' WHERE lkcampaigngroup.CampaignID = %d ';
  2116.  
  2117. $SQL = sprintf($SQL, $campaignId);
  2118.  
  2119. if (!$results = $db->query($SQL))
  2120. {
  2121. trigger_error($db->error());
  2122. trigger_error(__('Unable to get group information for layout'), E_USER_ERROR);
  2123. }
  2124.  
  2125. $groups = '';
  2126.  
  2127. while ($row = $db->get_assoc_row($results))
  2128. {
  2129. $groups .= $row['Group'] . ', ';
  2130. }
  2131.  
  2132. $groups = trim($groups);
  2133. $groups = trim($groups, ',');
  2134.  
  2135. return $groups;
  2136. }
  2137.  
  2138. /**
  2139. * A List of Layouts we have permission to design
  2140. */
  2141. public function LayoutJumpList()
  2142. {
  2143. $db =& $this->db;
  2144. $user =& $this->user;
  2145. $response = new ResponseManager();
  2146.  
  2147. // Show a list of layouts we have permission to jump to
  2148. $output = '<div class="info_table">';
  2149. $output .= '<table style="width:100%">';
  2150. $output .= ' <thead>';
  2151. $output .= ' <tr>';
  2152. $output .= ' <th>' . __('Layout') . '</th>';
  2153. $output .= ' <th>' . __('Action') . '</th>';
  2154. $output .= ' </tr>';
  2155. $output .= ' </thead>';
  2156. $output .= ' <tbody>';
  2157.  
  2158. // Get a layout list
  2159. $layoutList = $user->LayoutList();
  2160.  
  2161. foreach($layoutList as $layout)
  2162. {
  2163. if (!$layout['edit'] == 1)
  2164. continue;
  2165.  
  2166. // We have permission to edit this layout
  2167. $output .= '<tr>';
  2168. $output .= ' <td>' . $layout['layout'] . '</td>';
  2169. $output .= ' <td><button href="index.php?p=layout&modify=true&layoutid=' . $layout['layoutid'] . '" onclick="window.location = $(this).attr(\'href\')"><span>' . __('Design') . '</span></button></td>';
  2170. $output .= '</tr>';
  2171. }
  2172.  
  2173. $output .= ' </tbody>';
  2174. $output .= '</table>';
  2175. $output .= '</div>';
  2176.  
  2177. $response->SetFormRequestResponse($output, __('Jump to...'), '350px', '500px');
  2178. $response->AddButton(__('Close'), 'XiboDialogClose()');
  2179. $response->Respond();
  2180. }
  2181.  
  2182. /**
  2183. * A List of Regions we have permission to design
  2184. */
  2185. public function EditRegionList()
  2186. {
  2187. $db =& $this->db;
  2188. $user =& $this->user;
  2189. $response = new ResponseManager();
  2190.  
  2191. // Assume we have the xml in memory already
  2192. // Make a DOM from the XML
  2193. $xml = new DOMDocument();
  2194. $xml->loadXML($this->xml);
  2195.  
  2196. $layoutId = Kit::GetParam('layoutid', _REQUEST, _INT);
  2197.  
  2198. // Show a list of layouts we have permission to jump to
  2199. $output = '<div class="info_table">';
  2200. $output .= '<table style="width:100%">';
  2201. $output .= ' <thead>';
  2202. $output .= ' <tr>';
  2203. $output .= ' <th>' . __('Region') . '</th>';
  2204. $output .= ' <th>' . __('Name') . '</th>';
  2205. $output .= ' <th colspan="4">' . __('Actions') . '</th>';
  2206. $output .= ' </tr>';
  2207. $output .= ' </thead>';
  2208. $output .= ' <tbody>';
  2209.  
  2210. // Get all the regions and draw them on
  2211. $regionNodeList = $xml->getElementsByTagName('region');
  2212. $regionNum = 0;
  2213.  
  2214. //get the regions
  2215. foreach ($regionNodeList as $region)
  2216. {
  2217. // get dimensions
  2218. $top = $region->getAttribute('top');
  2219. $left = $region->getAttribute('left');
  2220. $width = $region->getAttribute('width');
  2221. $height = $region->getAttribute('height');
  2222. $regionId = $region->getAttribute('id');
  2223. $regionName = $region->getAttribute('name');
  2224. $regionNum = $regionNum + 1;
  2225.  
  2226. // We have permission to edit this layout
  2227. $output .= '<tr>';
  2228. $output .= ' <td>#' . $regionNum . '</td>';
  2229. $output .= ' <td>' . $regionName . '</td>';
  2230. // Timeline Button
  2231. $output .= ' <td><button class="XiboFormButton ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only ui-state-hover" href="index.php?p=layout&q=RegionOptions&layoutid=' . $layoutId . '&regionid=' . $regionId . '" role="button" aria-disabled="false"><span>' . __('Timeline') . '</span></button></td>';
  2232. // Options Button
  2233. $output .= ' <td><button class="XiboFormButton ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only ui-state-hover" href="index.php?p=layout&q=ManualRegionPositionForm&layoutid=' . $layoutId . '&regionid=' . $regionId . '&top=' . $top . '&left=' . $left . '&width=' . $width . '&height=' . $height . '" role="button" aria-disabled="false"><span>' . __('Options') . '</span></button></td>';
  2234. // Delete Button
  2235. $output .= ' <td><button class="XiboFormButton ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only ui-state-hover" href="index.php?p=layout&q=DeleteRegionForm&layoutid=' . $layoutId . '&regionid=' . $regionId . '" role="button" aria-disabled="false"><span>' . __('Delete') . '</span></button></td>';
  2236. // Permissions Button
  2237. $output .= ' <td><button class="XiboFormButton ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only ui-state-hover" href="index.php?p=layout&q=RegionPermissionsForm&layoutid=' . $layoutId . '&regionid=' . $regionId . '" role="button" aria-disabled="false"><span>' . __('Permissions') . '</span></button></td>';
  2238. $output .= '</tr>';
  2239.  
  2240. } // End of Region Loop
  2241.  
  2242. $output .= ' </tbody>';
  2243. $output .= '</table>';
  2244. $output .= '</div>';
  2245.  
  2246. $response->SetFormRequestResponse($output, __('Add/Edit Regions'), '600px', '500px');
  2247. $response->AddButton(__('Add Region'), 'addRegionButton("' .$layoutId . '"); XiboDialogClose();');
  2248. $response->AddButton(__('Close'), 'XiboDialogClose()');
  2249. $response->Respond();
  2250. }
  2251.  
  2252. /**
  2253. * A List of Regions for the Layers Tab
  2254. */
  2255. public function RegionLayersList($layoutId)
  2256. {
  2257. $db =& $this->db;
  2258. $user =& $this->user;
  2259. $response = new ResponseManager();
  2260.  
  2261. // Load Region Class
  2262. Kit::ClassLoader('region');
  2263. $regionClass = new region($db, $user);
  2264.  
  2265. // Assume we have the xml in memory already
  2266. // Make a DOM from the XML
  2267. $xml = new DOMDocument();
  2268. $xml->loadXML($this->xml);
  2269.  
  2270. //$layoutId = Kit::GetParam('layoutid', _REQUEST, _INT);
  2271. $output = '';
  2272.  
  2273. // Get all the regions and draw them on
  2274. $regionNodeList = $xml->getElementsByTagName('region');
  2275. $regionNum = 0;
  2276.  
  2277. //get the regions
  2278. foreach ($regionNodeList as $region)
  2279. {
  2280. // get dimensions
  2281. $top = $region->getAttribute('top');
  2282. $left = $region->getAttribute('left');
  2283. $width = $region->getAttribute('width');
  2284. $height = $region->getAttribute('height');
  2285. $regionId = $region->getAttribute('id');
  2286. $regionName = $region->getAttribute('name');
  2287. $regionOrder = $region->getAttribute('order');
  2288. if ($regionOrder == '')
  2289. {
  2290. // Increment the Region order counter
  2291. $regionOrder = $xml->documentElement->getAttribute('order');
  2292. $regionOrder = $regionOrder + 1;
  2293. $xml->documentElement->setAttribute('order', $regionOrder);
  2294. $region->setAttribute('order', $regionOrder);
  2295. //Write it back to the database
  2296. $saveXML = $xml->saveXML();
  2297. $saveXML = addslashes($saveXML);
  2298. $SQL = sprintf("UPDATE layout SET xml = '%s' WHERE layoutID = %d ", $saveXML, $layoutId);
  2299. if (!$db->query($SQL))
  2300. {
  2301. trigger_error("Unable to Update that layouts XML");
  2302. }
  2303. }
  2304. $regionNum = $regionNum + 1;
  2305. $regionHead = 'Region: ' . $regionOrder;
  2306. if ($regionName != '') {$regionHead .= ' - ' . $regionName;}
  2307.  
  2308. // We have permission to edit this layout
  2309.  
  2310. $output .= '<div style="margin-bottom:2px;" class="group" id="region_' . $regionNum . '" regionnum="' . $regionNum .
  2311. '" regionnum="' . $regionNum . '" regionid="' . $regionId . '">';
  2312. $output .= '<h3 style="padding-left:35px; margin:0px; font-size:17px;" align="left"><span id="rhead_' . $regionId .
  2313. '" regionorder="' . $regionOrder . '">' . $regionHead .
  2314. '</span></h3><div style=" padding-bottom:10px; padding-top:5px; ">';
  2315.  
  2316. $output .= '<form id="RegionInfo_' . $regionId . '" class="XiboForm" method="post" action="index.php?p=layout&q=ManualRegionPosition">
  2317. <input id="layoutid" type="hidden" name="layoutid">
  2318. <input id="regionid" type="hidden" name="regionid">
  2319. <input id="layoutWidth" type="hidden" name="layoutWidth">
  2320. <input id="layoutHeight" type="hidden" name="layoutHeight">
  2321. <table>
  2322. <tr>
  2323. <td><label for="regionName" title="Name of the Region">Name</label></td>
  2324. <td><input name="regionName_' . $regionId . '" type="text" id="regionName" tabindex="1" class="form-control"/></td>
  2325. </tr>
  2326. <tr>
  2327. <td><label for="regionTop" title="Offset from the Top Corner">Top Offset</label></td>
  2328. <td><input name="regionTop_' . $regionId . '" type="text" id="regionTop" tabindex="2" class="form-control"/></td>
  2329. </tr>
  2330. <tr>
  2331. <td><label for="regionLeft" title="Offset from the Left Corner">Left Offset</label></td>
  2332. <td><input name="regionLeft_' . $regionId . '" type="text" id="regionLeft" tabindex="3" class="form-control"/></td>
  2333. </tr>
  2334. <tr>
  2335. <td><label for="regionWidth" title="Width of the Region">Width</label></td>
  2336. <td><input name="regionWidth_' . $regionId . '" type="text" id="regionWidth" tabindex="4" class="form-control"/></td>
  2337. </tr>
  2338. <tr>
  2339. <td><label for="regionHeight" title="Height of the Region">Height</label></td>
  2340. <td><input name="regionHeight_' . $regionId . '" type="text" id="regionHeight" tabindex="5" class="form-control"/></td>
  2341. </tr>
  2342. <tr>
  2343. <td colspan="2">
  2344. <div style="text-align:center; margin-top:12px;">
  2345. <input id="regionBtnSave" type="button" value="Save"
  2346. class="btn btn-primary" style="width:40%"
  2347. onclick="submitRegionInfo(\'' . $regionId . '\')" / >
  2348.  
  2349. <input id="regionBtnDelete" type="button" value="Delete"
  2350. class="btn btn-primary" style="width:40%"
  2351. onclick="regionDelete(\'' . $regionId . '\');XiboDialogButtonClass();" / >
  2352. </div>
  2353. </br>
  2354. <div style="text-align:center">
  2355. <button id="regionBtnFullScreen" style="width:100%;margin-bottom:4px;" type="button" class="btn btn-default XiboFormButton" onclick="regionLayoutFull(\'' . $regionId . '\')">
  2356. Full <i class="glyphicon glyphicon-fullscreen"></i>
  2357. </button>
  2358. <button id="regionBtnTimeline" style="width:100%;margin-bottom:5px;" type="button" class="btn btn-primary XiboFormButton" onclick="regionTimeline(\'' . $regionId . '\')" >
  2359. Timeline <i class="glyphicon glyphicon-calendar"></i>
  2360. </button>
  2361. <button id="regionBtnPermissions" style="width:100%;margin-bottom:5px;" type="button" class="btn btn-success XiboFormButton" onclick="regionPermissions(\'' . $regionId . '\')" >
  2362. Permissions <i class="glyphicon glyphicon-lock"></i>
  2363. </button>
  2364.  
  2365. </div>
  2366. </td>
  2367. </tr>
  2368. </table>
  2369. </form>';
  2370.  
  2371. $output .= '</div></div>';
  2372.  
  2373. } // End of Region Loop
  2374.  
  2375. return $output;
  2376. }
  2377.  
  2378.  
  2379. /**
  2380. * Shows the TimeLine
  2381. */
  2382. public function Timeline()
  2383. {
  2384. $db =& $this->db;
  2385. $user =& $this->user;
  2386. $response = new ResponseManager();
  2387. $response->html = '';
  2388.  
  2389. $layoutId = Kit::GetParam('layoutid', _GET, _INT);
  2390. $regionId = Kit::GetParam('regionid', _REQUEST, _STRING);
  2391.  
  2392. // Make sure we have permission to edit this region
  2393. Kit::ClassLoader('region');
  2394. $region = new region($db, $user);
  2395. $ownerId = $region->GetOwnerId($layoutId, $regionId);
  2396. $regionName = $region->GetRegionName($layoutId, $regionId); // <nobrolchain@gmail.com>
  2397. if ($regionName != '') {$regionName = ' - ' . $regionName;}
  2398.  
  2399. $regionAuth = $this->user->RegionAssignmentAuth($ownerId, $layoutId, $regionId, true);
  2400. if (!$regionAuth->edit)
  2401. trigger_error(__('You do not have permissions to edit this region'), E_USER_ERROR);
  2402.  
  2403. // Library location
  2404. $libraryLocation = Config::GetSetting($db, 'LIBRARY_LOCATION');
  2405.  
  2406. // Present a canvas with 2 columns, left column for the media icons
  2407. $response->html .= '<div style="width:1000px;">';
  2408. $response->html .= '<div class="timelineLeftColumn">';
  2409. $response->html .= ' <ul class="nav nav-tabs">';
  2410. $response->html .= ' <li><a href="#primary" data-toggle="tab">Primary</a>';
  2411. $response->html .= ' </li>';
  2412. $response->html .= ' <li><a href="#extras" data-toggle="tab">Extras</a>';
  2413. $response->html .= ' </li>';
  2414. $response->html .= ' </ul>';
  2415. $response->html .= ' <div id="myTabContent" class="tab-content">';
  2416. $response->html .= ' <div id="primary" class="tab-pane fade active in body widget">';
  2417. $response->html .= ' <ul class="timelineModuleButtons">';
  2418.  
  2419. // Always output a Library assignment button
  2420. $response->html .= '<li class="timelineModuleListItem" style="width:31%">';
  2421. $response->html .= ' <a class="XiboFormButton timelineModuleButtonAnchor" title="' . __('Assign from Library') . '" href="index.php?p=content&q=LibraryAssignForm&layoutid=' . $layoutId . '&regionid=' . $regionId . '">';
  2422. $response->html .= ' <img style="float:center" class="timelineModuleButtonImage" src="img/forms/library.png" alt="' . __('Library Image') . '" />';
  2423. $response->html .= ' <span class="timelineModuleButtonText">' . __('Library') . '</span>';
  2424. $response->html .= ' </a>';
  2425. $response->html .= '</li>';
  2426.  
  2427. // Get a list of the enabled modules and then create buttons for them
  2428. if (!$enabledModules1 = new ModuleManager($db, $user))
  2429. trigger_error($enabledModules1->message, E_USER_ERROR);
  2430. while ($modulesItem1 = $enabledModules1->GetNextModule())
  2431. {
  2432. $mod = Kit::ValidateParam($modulesItem1['Module'], _STRING);
  2433. $mod = strtolower($mod);
  2434. if($mod == "image"){
  2435. $response->html .= '<li class="timelineModuleListItem" style="width:31%">';
  2436. $response->html .= ' <a class="XiboFormButton timelineModuleButtonAnchor" title="' . __('Images. PNG, JPG, BMP, GIF') . '" href="index.php?p=module&q=Exec&mod=image&method=AddForm&layoutid=' . $layoutId . '&regionid=' . $regionId . '">';
  2437. $response->html .= ' <img style="float:center" class="timelineModuleButtonImage" src="img/forms/image.gif" alt="' . __('Image image') . '" />';
  2438. $response->html .= ' <span class="timelineModuleButtonText">' . __('Image'). '</span>';
  2439. $response->html .= ' </a>';
  2440. $response->html .= '</li>';
  2441. }
  2442. if($mod == "video"){
  2443. $response->html .= '<li class="timelineModuleListItem" style="width:31%">';
  2444. $response->html .= ' <a class="XiboFormButton timelineModuleButtonAnchor" title="' . __('Videos. MP4, WMV.') . '" href="index.php?p=module&q=Exec&mod=video&method=AddForm&layoutid=' . $layoutId . '&regionid=' . $regionId . '">';
  2445. $response->html .= ' <img style="float:center" class="timelineModuleButtonImage" src="img/forms/video.gif" alt="' . __('Image image') . '" />';
  2446. $response->html .= ' <span class="timelineModuleButtonText">' . __('Video'). '</span>';
  2447. $response->html .= ' </a>';
  2448. $response->html .= '</li>';
  2449. }
  2450. }
  2451. if (!$enabledModules = new ModuleManager($db, $user))
  2452. trigger_error($enabledModules->message, E_USER_ERROR);
  2453. // Loop through the buttons we have and output each one
  2454. while ($modulesItem = $enabledModules->GetNextModule())
  2455. {
  2456. $mod = Kit::ValidateParam($modulesItem['Module'], _STRING);
  2457. $caption = Kit::ValidateParam($modulesItem['Name'], _STRING);
  2458. $mod = strtolower($mod);
  2459. $title = Kit::ValidateParam($modulesItem['Description'], _STRING);
  2460. $img = Kit::ValidateParam($modulesItem['ImageUri'], _STRING);
  2461.  
  2462. $uri = 'index.php?p=module&q=Exec&mod=' . $mod . '&method=AddForm&layoutid=' . $layoutId . '&regionid=' . $regionId;
  2463.  
  2464. if($mod == "text" || $mod == "ticker" || $mod == "webpage" || $mod == "youtube"){
  2465. $response->html .= '<li class="timelineModuleListItem">';
  2466. $response->html .= ' <a class="XiboFormButton timelineModuleButtonAnchor" title="' . $title . '" href="' . $uri . '">';
  2467. $response->html .= ' <img style="float:center" class="timelineModuleButtonImage" src="' . $img . '" alt="' . __('Module Image') . '" />';
  2468. $response->html .= ' <span class="timelineModuleButtonText">' . $caption . '</span>';
  2469. $response->html .= ' </a>';
  2470. $response->html .= '</li>';
  2471. }
  2472. }
  2473.  
  2474. $response->html .= ' </ul>';
  2475. $response->html .= ' </div>';
  2476. $response->html .= ' <div id="extras" class="tab-pane fade widget">';
  2477. $response->html .= ' <ul class="timelineModuleButtons">';
  2478. // Get a list of the enabled modules and then create buttons for them
  2479. if (!$enabledModules = new ModuleManager($db, $user))
  2480. trigger_error($enabledModules->message, E_USER_ERROR);
  2481.  
  2482. // Loop through the buttons we have and output each one
  2483. while ($modulesItem = $enabledModules->GetNextModule())
  2484. {
  2485. $mod = Kit::ValidateParam($modulesItem['Module'], _STRING);
  2486. $caption = Kit::ValidateParam($modulesItem['Name'], _STRING);
  2487. $mod = strtolower($mod);
  2488. $title = Kit::ValidateParam($modulesItem['Description'], _STRING);
  2489. $img = Kit::ValidateParam($modulesItem['ImageUri'], _STRING);
  2490.  
  2491. $uri = 'index.php?p=module&q=Exec&mod=' . $mod . '&method=AddForm&layoutid=' . $layoutId . '&regionid=' . $regionId;
  2492. if($mod != "text" && $mod != "ticker" && $mod != "webpage" && $mod != "youtube" && $mod != "image" && $mod != "video"){
  2493. $response->html .= '<li class="timelineModuleListItem" style="height:120px;">';
  2494. $response->html .= ' <a class="XiboFormButton timelineModuleButtonAnchor" title="' . $title . '" href="' . $uri . '">';
  2495. $response->html .= ' <img style="float:center" class="timelineModuleButtonImage" src="' . $img . '" alt="' . __('Module Image') . '" />';
  2496. $response->html .= ' <span class="timelineModuleButtonText">' . $caption . '</span>';
  2497. $response->html .= ' </a>';
  2498. $response->html .= '</li>';
  2499. }
  2500.  
  2501. }
  2502.  
  2503. $response->html .= ' </ul>';
  2504. $response->html .= ' </div>';
  2505. $response->html .= '</div>';
  2506. $response->html .= '</div>';
  2507.  
  2508. // Load the XML for this layout and region, we need to get the media nodes.
  2509. // These form the timeline and go in the right column
  2510.  
  2511. // Generate an ID for the list (this is passed into the reorder function)
  2512. $timeListMediaListId = uniqid('timelineMediaList_');
  2513.  
  2514. $response->html .= '<div id="timelineControl" class="timelineRightColumn" layoutid="' . $layoutId . '" regionid="' . $regionId . '">';
  2515. $response->html .= ' <p style="color:rgba(251,251,251,0.4);margin-left:5px;"> Region Timeline</p>';
  2516. $response->html .= ' <div class="timelineMediaVerticalList">';
  2517. $response->html .= ' <ul id="' . $timeListMediaListId . '" class="timelineSortableListOfMedia">';
  2518.  
  2519. // How are we going to colour the bars, my media type or my permissions
  2520. $timeBarColouring = Config::GetSetting($db, 'REGION_OPTIONS_COLOURING');
  2521.  
  2522. // Create a layout object
  2523. $layout = new Layout($db);
  2524.  
  2525. foreach($layout->GetMediaNodeList($layoutId, $regionId) as $mediaNode)
  2526. {
  2527. // Put this node vertically in the region timeline
  2528. $mediaId = $mediaNode->getAttribute('id');
  2529. $lkId = $mediaNode->getAttribute('lkid');
  2530. $mediaType = $mediaNode->getAttribute('type');
  2531. $mediaDuration = $mediaNode->getAttribute('duration');
  2532. $ownerId = $mediaNode->getAttribute('userId');
  2533. $directionNode = $mediaNode->getElementsByTagName('direction');
  2534. $direction = 'none'; // Set default value
  2535. if (!is_null($directionNode->item(0)) && $directionNode->item(0)->nodeValue != '') {$direction = $directionNode->item(0)->nodeValue;}
  2536. $durationType = __('Seconds');
  2537. if ($mediaType == "text" && ($direction == 'left' || $direction == 'right' || $direction == 'up' || $direction == 'down'))
  2538. {$durationType = __('Occurrences');}
  2539. if ($mediaType == "geoloc")
  2540. {$durationType = __('GeoLocation ');}
  2541. if ($mediaType == "subtitle")
  2542. {$durationType = "";}
  2543. // Permissions for this assignment
  2544. $auth = $user->MediaAssignmentAuth($ownerId, $layoutId, $regionId, $mediaId, true);
  2545.  
  2546. // Skip over media assignments that we do not have permission to see
  2547. if (!$auth->view)
  2548. continue;
  2549.  
  2550. Debug::LogEntry($db, 'audit', sprintf('Permission Granted to View MediaID: %s', $mediaId), 'layout', 'TimeLine');
  2551.  
  2552. // Create a media module to handle all the complex stuff
  2553. require_once("modules/$mediaType.module.php");
  2554. $tmpModule = new $mediaType($db, $user, $mediaId, $layoutId, $regionId, $lkId);
  2555. $mediaName = $tmpModule->GetName();
  2556.  
  2557. // Colouring for the media block
  2558. $moduleColor = '';
  2559. $moduleColorCode = '';
  2560. $sql = "SELECT color FROM module ";
  2561. $sql .= sprintf(" WHERE Module = '%s'", $mediaType);
  2562. if(!$results = $db->query($sql))
  2563. {
  2564. trigger_error($db->error());
  2565. trigger_error(__("Cannot retrieve color from the module table"), E_USER_ERROR);
  2566. }
  2567. while($Row = $db->get_row($results))
  2568. {
  2569. $moduleColor = $Row[0];
  2570. $moduleColorCode = $Row[0];
  2571. }
  2572. if ($moduleColor == NULL)
  2573. {
  2574. $moduleColor = '';
  2575. $moduleColorCode = '';
  2576. if ($timeBarColouring == 'Media Colouring')
  2577. {$mediaBlockColouringClass = 'timelineMediaItemColouring_' . $mediaType;}
  2578. else
  2579. {$mediaBlockColouringClass = 'timelineMediaItemColouring_' . (($auth->edit) ? 'enabled' : 'disabled');}
  2580. }
  2581. else
  2582. {
  2583. $moduleColor = ' style="background-color:#' . $moduleColor . ';"';
  2584. $mediaBlockColouringClass = '';
  2585. }
  2586.  
  2587. /* if ($timeBarColouring == 'Media Colouring')
  2588. {$mediaBlockColouringClass = 'timelineMediaItemColouring_' . $mediaType;}
  2589. else
  2590. {$mediaBlockColouringClass = 'timelineMediaItemColouring_' . (($auth->edit) ? 'enabled' : 'disabled');}
  2591. */
  2592.  
  2593. // Create the list item
  2594.  
  2595. $response->html .= '<li class="timelineMediaListItem" mediaid="' . $mediaId . '" lkid="' . $lkId . '">';
  2596. $response->html .= ' <div class="timelineMediaItem" style="border-style: solid;border-width: 1px; border-color:#'.$moduleColorCode.';"">';
  2597. $response->html .= ' <ul class="timelineMediaItemLinks">';
  2598. // $response->html .= ' <li class="timelinecolour"' . $moduleColor . '>rttr</li>';
  2599. $response->html .= ' <div class="timelineMediaImageThumbnail">' . $tmpModule->ImageThumbnail() . '</div>';
  2600. $response->html .= ' <li class="limitWidth" style="max-width: 350px; display:inline;padding-left: 0px;"><h3 style="display:inline;max-width:150px;margin:0px;" >' . (($mediaName == '') ? $tmpModule->displayType : (( $mediaType == "subtitle")?substr($mediaName,0,30):substr($mediaName,0,15))) . '</br></h3><h3 style="display:inline;max-width:150px;margin:0px;" class="secondsText" > (' . $mediaDuration . ' ' . $durationType . ')</h3></li>';
  2601.  
  2602. // Create some links
  2603. if ($auth->modifyPermissions)
  2604. $response->html .= '<li class="floatRight"><a class="XiboFormButton timelineMediaBarLink" href="index.php?p=module&mod=' . $mediaType . '&q=Exec&method=PermissionsForm&layoutid=' . $layoutId . '&regionid=' . $regionId . '&mediaid=' . $mediaId . '&lkid=' . $lkId . '" title="Click to change permissions for this media"><span class="glyphicon glyphicon-lock"></span></a></li>';
  2605.  
  2606. if ($auth->del)
  2607. $response->html .= '<li class="floatRight"><a class="XiboFormButton timelineMediaBarLink" href="index.php?p=module&mod=' . $mediaType . '&q=Exec&method=DeleteForm&layoutid=' . $layoutId . '&regionid=' . $regionId . '&mediaid=' . $mediaId . '&lkid=' . $lkId . '" title="' . __('Click to delete this media') . '"><span class="glyphicon glyphicon-remove"></span></a></li>';
  2608.  
  2609. if ($auth->edit && $mediaType !== 'subtitle')
  2610. $response->html .= '<li class="floatRight"><a class="XiboFormButton timelineMediaBarLink" href="index.php?p=module&mod=' . $mediaType . '&q=Exec&method=EditForm&layoutid=' . $layoutId . '&regionid=' . $regionId . '&mediaid=' . $mediaId . '&lkid=' . $lkId . '" title="' . __('Click to edit this media') . '"><span class="glyphicon glyphicon-edit"></span></a></li>';
  2611.  
  2612.  
  2613. $response->html .= ' </ul>';
  2614.  
  2615. // // Put the media name in
  2616. $response->html .= ' <div class="timelineMediaDetails ' . $mediaBlockColouringClass . '"' . $moduleColor . '>';
  2617. $response->html .= ' <div class="limitWidth" style="max-width: 350px"></div>';
  2618. // $response->html .= ' <div class="limitWidth" style="max-width: 350px"><h3>' . (($mediaName == '') ? $tmpModule->displayType : (( $mediaType == "subtitle")?substr($mediaName,0,30):substr($mediaName,0,15))) . ' (' . $mediaDuration . ' ' . $durationType . ')</h3></div>';
  2619. // $response->html .= ' <div class="timelineMediaImageThumbnail">' . $tmpModule->ImageThumbnail() . '</div>';
  2620. $response->html .= ' </div>';
  2621.  
  2622. // Put the media hover preview in
  2623. $mediaHoverPreview = $tmpModule->HoverPreview();
  2624. $response->html .= ' <div class="timelineMediaPreview">' . $mediaHoverPreview . '</div>';
  2625.  
  2626. // End the time line media item and list
  2627. $response->html .= ' </div>';
  2628. $response->html .= '</li>';
  2629. }
  2630.  
  2631. $response->html .= ' </ul>';
  2632. $response->html .= ' </div>';
  2633. $response->html .= '</div>';
  2634.  
  2635. // Output a div to contain the preview for this media item
  2636. $response->html .= ' <div id="timelinePreview"></div>';
  2637.  
  2638. $response->html .= '</div>';
  2639.  
  2640. // Finish constructing the response
  2641. $response->callBack = 'LoadTimeLineCallback';
  2642. $response->dialogTitle = __('Region Timeline' . $regionName);
  2643. $response->dialogSize = true;
  2644. $response->dialogWidth = '1000px';
  2645. $response->dialogHeight = '550px';
  2646. $response->focusInFirstInput = false;
  2647.  
  2648. // Add some buttons
  2649. $response->AddButton(__('Save Order'), 'XiboTimelineSaveOrder("' . $timeListMediaListId . '","' . $layoutId . '","' . $regionId . '")');
  2650. $response->AddButton(__('Close'), 'XiboDialogClose()');
  2651. // $response->AddButton(__('Help'), 'XiboHelpRender("' . HelpManager::Link('Layout', 'RegionOptions') . '")');
  2652.  
  2653. $response->html .= '</div>';
  2654. $response->Respond();
  2655. }
  2656.  
  2657. /**
  2658. * Re-orders a medias regions
  2659. * @return
  2660. */
  2661. function TimelineReorder()
  2662. {
  2663. $db =& $this->db;
  2664. $user =& $this->user;
  2665. $response = new ResponseManager();
  2666.  
  2667. // Vars
  2668. $layoutId = Kit::GetParam('layoutid', _REQUEST, _INT);
  2669. $regionId = Kit::GetParam('regionid', _POST, _STRING);
  2670. $mediaList = Kit::GetParam('medialist', _POST, _STRING);
  2671.  
  2672. // Check the user has permission
  2673. Kit::ClassLoader('region');
  2674. $region = new region($db, $user);
  2675. $ownerId = $region->GetOwnerId($layoutId, $regionId);
  2676.  
  2677. $regionAuth = $this->user->RegionAssignmentAuth($ownerId, $layoutId, $regionId, true);
  2678. if (!$regionAuth->edit)
  2679. trigger_error(__('You do not have permissions to edit this region'), E_USER_ERROR);
  2680.  
  2681. // Create a list of media
  2682. if ($mediaList == '')
  2683. trigger_error(__('No media to reorder'));
  2684.  
  2685. // Trim the last | if there is one
  2686. $mediaList = rtrim($mediaList, '|');
  2687.  
  2688. // Explode into an array
  2689. $mediaList = explode('|', $mediaList);
  2690.  
  2691. // Store in an array
  2692. $resolvedMedia = array();
  2693.  
  2694. foreach($mediaList as $mediaNode)
  2695. {
  2696. // Explode the second part of the array
  2697. $mediaNode = explode('&', $mediaNode);
  2698.  
  2699. $resolvedMedia[] = array('mediaid' => $mediaNode[0], 'lkid' => $mediaNode[1]);
  2700. }
  2701.  
  2702. // Hand off to the region object to do the actual reorder
  2703. if (!$region->ReorderTimeline($layoutId, $regionId, $resolvedMedia))
  2704. trigger_error($region->errorMsg, E_USER_ERROR);
  2705.  
  2706. $response->SetFormSubmitResponse(__('Order Changed'));
  2707. $response->keepOpen = true;
  2708. $response->Respond();
  2709. }
  2710.  
  2711. /**
  2712. * Re-orders a regions within a layout
  2713. * @return
  2714. */
  2715. function RegionReorder()
  2716. {
  2717. $db =& $this->db;
  2718. $user =& $this->user;
  2719. $response = new ResponseManager();
  2720.  
  2721. // Vars
  2722. $layoutId = Kit::GetParam('layoutid', _REQUEST, _INT);
  2723. $regionList = Kit::GetParam('regionlist', _POST, _STRING);
  2724.  
  2725. // Create a comma separated string containing the regions
  2726. $regionExplode = explode('&', $regionList);
  2727. $regionIds = '';
  2728. foreach($regionExplode as $regionItem)
  2729. {
  2730. if ($regionItem != '')
  2731. {
  2732. // Look for regionid
  2733. $regionIds .= $regionItem;
  2734. $regionIds .= ',';
  2735. }
  2736. }
  2737. $regionIds = rtrim( $regionIds, ',');
  2738.  
  2739. // Create a Layout object
  2740. Kit::ClassLoader('region');
  2741. $region = new region($db,$user);
  2742.  
  2743. // Create a list of regions
  2744. if ($regionList == '')
  2745. trigger_error(__('No regions to reorder'));
  2746.  
  2747. // Trim the last | if there is one
  2748. $regionList = rtrim($regionList, '&');
  2749.  
  2750. // Hand off to the layout object to do the actual reorder
  2751. if (!$region->ReorderRegions($layoutId, $regionList))
  2752. trigger_error($region->errorMsg, E_USER_ERROR);
  2753.  
  2754. // Refresh design screen
  2755. $sql = "SELECT xml FROM layout ";
  2756. $sql .= sprintf(" WHERE layoutID = %d;", $layoutId);
  2757. if(!$results = $db->query($sql))
  2758. {
  2759. trigger_error($db->error());
  2760. trigger_error(__("Cannot retrieve XML relating to this layout. The layout may be corrupt."), E_USER_ERROR);
  2761. }
  2762. while($Row = $db->get_row($results))
  2763. {
  2764. $this->xml = $Row[0];
  2765. }
  2766.  
  2767. //$response->SetFormSubmitResponse(__('Order Changed'));
  2768. $response->callBack = "region_refresh('" . $regionIds . "')";
  2769. //$response->keepOpen = true;
  2770. $response->Respond();
  2771. }
  2772.  
  2773. }
  2774. ?>
Add Comment
Please, Sign In to add comment