PageRenderTime 57ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/templates/eimadmin/projectActivity.php

https://github.com/solusee/OrangeEarthstoneHRM
PHP | 418 lines | 310 code | 48 blank | 60 comment | 47 complexity | 27e065ce21e4391968eac4a6b61a7e12 MD5 | raw file
  1. <?php
  2. /**
  3. * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
  4. * all the essential functionalities required for any enterprise.
  5. * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
  6. *
  7. * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
  8. * the GNU General Public License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  12. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with this program;
  16. * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. * Boston, MA 02110-1301, USA
  18. */
  19. require_once ROOT_PATH . '/lib/confs/sysConf.php';
  20. require_once ROOT_PATH . '/lib/models/eimadmin/Projects.php';
  21. require_once ROOT_PATH . '/lib/models/eimadmin/ProjectActivity.php';
  22. require_once($lan->getLangPath("full.php"));
  23. $locRights=$_SESSION['localRights'];
  24. if ($locRights['edit']) {
  25. $disableEdit = "";
  26. $addBtnAction = "displayAddLayer()";
  27. $saveBtnAction= "saveActivity()";
  28. $delBtnAction = "deleteActivities()";
  29. $selectProjectAction = "selectProject()";
  30. $cancelBtnAction = "cancelEdit()";
  31. } else {
  32. $disableEdit = 'disabled = "true"';
  33. $addBtnAction = "showAccessDeniedMsg()";
  34. $saveBtnAction="showAccessDeniedMsg()";
  35. $delBtnAction = "showAccessDeniedMsg()";
  36. $selectProjectAction = "";
  37. $cancelBtnAction = "showAccessDeniedMsg()";
  38. }
  39. $projects = $this->popArr['projects'];
  40. $projectId = $this->popArr['projectId'];
  41. $activities = $this->popArr['activities'];
  42. $formAction = "{$_SERVER['PHP_SELF']}?uniqcode=PAC";
  43. if (!empty($projectId)) {
  44. $formAction .= "&projectId={$projectId}";
  45. }
  46. ?>
  47. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  48. <html xmlns="http://www.w3.org/1999/xhtml">
  49. <head>
  50. <title><?php echo $lang_Admin_ProjectActivities; ?></title>
  51. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  52. <script type="text/javascript" src="../../scripts/archive.js"></script>
  53. <script type="text/javascript">
  54. //<![CDATA[
  55. /** Global edit mode of form */
  56. var addMode = true;
  57. /**
  58. * Add a new project activity
  59. */
  60. function saveActivity() {
  61. if (validateFields()) {
  62. formAction = "<?php echo $formAction; ?>";
  63. with (document.frmActivity) {
  64. if (addMode) {
  65. action = formAction;
  66. sqlState.value = "NewRecord";
  67. } else {
  68. action = formAction + "&id=" + activityId.value;
  69. sqlState.value = "UpdateRecord";
  70. }
  71. }
  72. document.frmActivity.submit();
  73. }
  74. }
  75. /**
  76. * Validates the form fields in the form
  77. * returns true if validated, false otherwise.
  78. */
  79. function validateFields() {
  80. var name = document.frmActivity.activityName;
  81. if(name.value == '') {
  82. alert("<?php echo $lang_Admin_Project_Activity_Error_PleaseSpecifyTheActivityName; ?>");
  83. name.focus();
  84. return false;
  85. }
  86. if (isDuplicateName(trim(name.value))) {
  87. alert("<?php echo $lang_Admin_Project_Activity_Error_NameAlreadyDefined; ?>");
  88. name.focus();
  89. return false;
  90. }
  91. return true;
  92. }
  93. /**
  94. * Checks if an activity with the given name already exists in this project
  95. */
  96. function isDuplicateName(name) {
  97. var duplicate = false;
  98. var activityNames = new Array();
  99. <?php
  100. for ($i=0; $i<count($activities); $i++) {
  101. echo "activityNames[{$i}] = \"" . CommonFunctions::escapeForJavascript($activities[$i]->getName()) . "\";";
  102. }
  103. ?>
  104. for (var i=0; i < activityNames.length; i++) {
  105. if (activityNames[i] == name) {
  106. duplicate = true;
  107. break;
  108. }
  109. }
  110. return duplicate;
  111. }
  112. /**
  113. * Show acccess denied message.
  114. */
  115. function showAccessDeniedMsg() {
  116. alert("<?php echo $lang_Error_AccessDenied; ?>")
  117. }
  118. /**
  119. * Run when the "add" button is clicked.
  120. * Shows the employee select fields
  121. */
  122. function displayAddLayer() {
  123. document.getElementById("addActivityLayer").style.display = 'block';
  124. document.getElementById("addActivityLayer").style.float = 'left';
  125. }
  126. /**
  127. * Run when the cancel button is pressed
  128. */
  129. function cancelEdit() {
  130. document.getElementById("addActivityLayer").style.display = 'none';
  131. document.frmActivity.activityName.value = "";
  132. document.frmActivity.activityId.value = "";
  133. addMode = true;
  134. }
  135. /**
  136. * Check or uncheck all project activity check boxes.
  137. */
  138. function checkUncheckAll() {
  139. var projectId = document.frmActivity.cmbProjectId.value;
  140. document.frmActivity.action = "./CentralController.php?uniqcode=PAC&VIEW=MAIN&projectId=" + projectId;
  141. var checked;
  142. with (document.frmActivity) {
  143. checked = elements['allCheck'].checked;
  144. for (var i=0; i < elements.length; i++) {
  145. if (elements[i].type == 'checkbox') {
  146. elements[i].checked = checked;
  147. }
  148. }
  149. }
  150. }
  151. /**
  152. * If at least one activity is unchecked, main check box would be unchecked
  153. */
  154. function unCheckMain() {
  155. var allCheck = document.frmActivity.allCheck;
  156. with (document.frmActivity) {
  157. for (var i=0; i < elements.length; i++) {
  158. if (elements[i].type == 'checkbox' && elements[i] != allCheck && elements[i].checked == true) {
  159. allCheck.checked = false;
  160. return;
  161. }
  162. }
  163. }
  164. }
  165. /**
  166. * When a check box is clicked, form action is changed according to selected ProjectID
  167. */
  168. function setFormAction() {
  169. unCheckMain();
  170. var projectId = document.frmActivity.cmbProjectId.value;
  171. document.frmActivity.action = "./CentralController.php?uniqcode=PAC&VIEW=MAIN&projectId=" + projectId;
  172. }
  173. /**
  174. * Delete selected activities.
  175. */
  176. function deleteActivities() {
  177. var check = false;
  178. with (document.frmActivity) {
  179. for (var i=0; i < elements.length; i++) {
  180. if ((elements[i].type == 'checkbox') && (elements[i].checked == true)){
  181. check = true;
  182. break;
  183. }
  184. }
  185. if (check) {
  186. delState.value = 'DeleteMode';
  187. submit();
  188. } else {
  189. alert("<?php echo $lang_Error_SelectAtLeastOneRecordToDelete; ?>");
  190. }
  191. }
  192. }
  193. /**
  194. * Change the selected project
  195. */
  196. function selectProject() {
  197. var projectId = document.frmActivity.cmbProjectId.value;
  198. location.href = "./CentralController.php?uniqcode=PAC&VIEW=MAIN&projectId=" + projectId;
  199. }
  200. /**
  201. * Edit the given activity's name
  202. */
  203. function editActivity(activityId, activityName) {
  204. activityName = replaceAll('&amp;', '&', activityName);
  205. activityName = replaceAll('&lt;', '<', activityName);
  206. activityName = replaceAll('&gt;', '>', activityName);
  207. document.frmActivity.activityName.value = activityName;
  208. document.frmActivity.activityId.value = activityId;
  209. if (addMode) {
  210. addMode = false;
  211. }
  212. displayAddLayer();
  213. }
  214. function replaceAll(needle, replacement, haystack) {
  215. while (haystack.indexOf(needle) != -1) {
  216. haystack = haystack.replace(needle, replacement);
  217. }
  218. return haystack;
  219. }
  220. //]]>
  221. </script>
  222. <script type="text/javascript" src="../../themes/<?php echo $styleSheet;?>/scripts/style.js"></script>
  223. <link href="../../themes/<?php echo $styleSheet;?>/css/style.css" rel="stylesheet" type="text/css"/>
  224. <!--[if lte IE 6]>
  225. <link href="../../themes/<?php echo $styleSheet; ?>/css/IE6_style.css" rel="stylesheet" type="text/css"/>
  226. <![endif]-->
  227. <!--[if IE]>
  228. <link href="../../themes/<?php echo $styleSheet; ?>/css/IE_style.css" rel="stylesheet" type="text/css"/>
  229. <![endif]-->
  230. </head>
  231. <body>
  232. <div class="formpage">
  233. <div class="outerbox">
  234. <div class="mainHeading"><h2><?php echo $lang_Admin_ProjectActivities;?></h2></div>
  235. <?php $message = isset($this->getArr['msg']) ? $this->getArr['msg'] : (isset($this->getArr['message']) ? $this->getArr['message'] : null);
  236. if (isset($message)) {
  237. $messageType = CommonFunctions::getCssClassForMessage($message);
  238. $message = "lang_Common_" . $message;
  239. ?>
  240. <div class="messagebar">
  241. <span class="<?php echo $messageType; ?>"><?php echo (isset($$message)) ? $$message: ""; ?></span>
  242. </div>
  243. <?php } ?>
  244. <?php if (empty($projects)) { ?>
  245. <div class="notice"><?php echo $lang_Admin_Project_Error_NoProjects; ?></div>
  246. <?php
  247. } else {
  248. ?>
  249. <form name="frmActivity" method="post" action="<?php echo $formAction;?>">
  250. <input type="hidden" name="sqlState" value=""/>
  251. <input type="hidden" name="delState" value=""/>
  252. <input type="hidden" name="activityId" value=""/>
  253. <label for="cmbProjectId"><?php echo $lang_Admin_Project; ?></label>
  254. <select id="cmbProjectId" name="cmbProjectId" onchange="<?php echo $selectProjectAction; ?>;"
  255. class="formSelect">
  256. <?php
  257. foreach ($projects as $project) {
  258. $selected = ($project->getProjectId() == $projectId) ? 'selected="selected"' : '';
  259. $projectName = $project->getProjectName();
  260. $customerName = $project->getCustomerName();
  261. $displayString = $customerName . ' - ' . $projectName;
  262. echo "<option $selected value=\"{$project->getProjectId()}\">{$displayString}</option>";
  263. }
  264. ?>
  265. </select>
  266. <br class="clear"/>
  267. <hr style="width:420px;float:left;margin:15px 0px 15px 0px"/>
  268. <br class="clear"/>
  269. <?php if (empty($activities)) { ?>
  270. <div class="notice"><?php echo $lang_Admin_Project_NoActivitiesDefined; ?></div>
  271. <?php } else { ?>
  272. <div style="float:left">
  273. <table width="250" class="simpleList" >
  274. <thead>
  275. <tr>
  276. <th class="listViewThS1">
  277. <input type='checkbox' class='checkbox' name='allCheck' value=''
  278. <?php echo $disableEdit; ?> onclick="checkUncheckAll();"/>
  279. </th>
  280. <th class="listViewThS1"><?php echo $lang_Admin_Activity; ?></th>
  281. </tr>
  282. </thead>
  283. <?php
  284. $odd = false;
  285. foreach ($activities as $activity) {
  286. $cssClass = ($odd) ? 'even' : 'odd';
  287. $odd = !$odd;
  288. ?>
  289. <tr>
  290. <td class="<?php echo $cssClass?>">
  291. <input type='checkbox' class='checkbox' name='chkLocID[]'
  292. <?php echo $disableEdit; ?> value='<?php echo $activity->getId();?>' onclick="setFormAction();"/>
  293. </td>
  294. <td class="<?php echo $cssClass?>">
  295. <?php
  296. $activityName = htmlspecialchars($activity->getName(),ENT_QUOTES);
  297. $activityId = $activity->getId();
  298. if (empty($disableEdit)) {
  299. echo "<a href=\"#\" onclick=\"editActivity({$activityId}, this.innerHTML);\">{$activityName}</a>";
  300. } else {
  301. echo $activityName;
  302. }
  303. ?>
  304. </td>
  305. </tr>
  306. <?php
  307. }
  308. ?>
  309. </table>
  310. </div>
  311. <?php
  312. }
  313. ?>
  314. <br class="clear"/>
  315. <div class="formbuttons">
  316. <?php if($locRights['edit']) { ?>
  317. <input type="button" class="savebutton" id="saveBtn"
  318. onclick="<?php echo $addBtnAction; ?>;" tabindex="4" onmouseover="moverButton(this);" onmouseout="moutButton(this);"
  319. value="<?php echo $lang_Common_Add;?>" />
  320. <?php
  321. if (!empty($activities)) {
  322. ?>
  323. <input type="button" class="clearbutton" onclick="<?php echo $delBtnAction;?>" tabindex="5"
  324. onmouseover="moverButton(this);" onmouseout="moutButton(this);"
  325. value="<?php echo $lang_Common_Delete;?>" />
  326. <?php
  327. }
  328. ?>
  329. <?php } ?>
  330. </div>
  331. <br class="clear"/>
  332. <div id ="addActivityLayer" style="display:none;">
  333. <label for="activityName"><?php echo $lang_Admin_Activity; ?></label>
  334. <input type="text" name="activityName" id="activityName" value="" class="formInputText" maxlength="60" />
  335. <br class="clear"/>
  336. <div class="formbuttons">
  337. <?php if($locRights['edit']) { ?>
  338. <input type="button" class="savebutton" id="adminSaveBtn"
  339. onclick="<?php echo $saveBtnAction; ?>;" tabindex="7" onmouseover="moverButton(this);" onmouseout="moutButton(this);"
  340. value="<?php echo $lang_Common_Save;?>" />
  341. <input type="button" class="clearbutton" onclick="<?php echo $cancelBtnAction;?>" tabindex="8"
  342. id="adminCancelBtn"
  343. onmouseover="moverButton(this);" onmouseout="moutButton(this);"
  344. value="<?php echo $lang_Common_Cancel;?>" />
  345. <?php } ?>
  346. </div>
  347. <?php
  348. ?>
  349. </div>
  350. <br class="clear"/>
  351. </form>
  352. </div>
  353. <script type="text/javascript">
  354. //<![CDATA[
  355. if (document.getElementById && document.createElement) {
  356. roundBorder('outerbox');
  357. }
  358. //]]>
  359. </script>
  360. <?php
  361. }
  362. if (!empty($activities)) {
  363. ?>
  364. <div id="notice"><?php echo $lang_Admin_Project_Activity_ClickOnActivityToEdit; ?>.</div>
  365. <?php
  366. }
  367. ?>
  368. </div>
  369. </body>
  370. </html>