jobs.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <?
  2. if (!$logged_me_in_successfully234)
  3. return;
  4. if (!isset($jobamount))
  5. $jobamount = 5;
  6. if ($new == "1")
  7. {
  8. $Subtaskarr = GrabTasktypes("subs");
  9. echo '<form onsubmit="return CheckSubtasks(this);" action="?act=jobs" method="post">
  10. <b>Введите данные новой должности:</b>
  11. <br>
  12. <p>Название: <input name="jobname"></p>
  13. <p><b>Доступные типы команд:</b><br>';
  14. echo "<div id='taskcont'>";
  15. ShowTasksSelect($Subtaskarr, 0, 'selectstring', "subtask");
  16. echo "</div>";
  17. echo '<input type="submit" value="Добавить">
  18. <input type=\'hidden\' name=\'new\' value=\'2\'>
  19. </form>';
  20. echo '<p></p><a href="?act=jobs">Вернуться к списку должностей</a></p>';
  21. }
  22. else
  23. {
  24. if ($new == "2")
  25. {
  26. $subtask_arr = FillArrayString("subtask", true);
  27. echo "<span style='color:green'><b>Запись добавлена!</b></span>";
  28. $jobtype = new Jobtype();
  29. foreach ($subtask_arr as $tasktype_id)
  30. {
  31. if ($tasktype_id) {
  32. $tasktype = Tasktype::Find($tasktype_id);
  33. $jobtype->name = $jobname;
  34. $jobtype->setCompany($companyID);
  35. $jobtype->addTasktype($tasktype);
  36. $tasktype->Save();
  37. }
  38. }
  39. $jobtype->Save();
  40. }
  41. else if ($new == "3")
  42. {
  43. $pt = Jobtype::Find($del_id);
  44. $tts = $pt->getTaskTypes();
  45. foreach ($tts as $tt) {
  46. $pt->deleteTasktype($tt);
  47. $tt->Save();
  48. }
  49. Jobtype::Delete($del_id);
  50. echo "<span style='color:red'><b>Должность $del_id удалена!</b></span>";
  51. mysqli_query($link, "delete from jobtypes where id =".$del_id);
  52. }
  53. if ($new == "5")
  54. {
  55. //CHANGE tasktype of jobtype!
  56. $newtask_jobtype = Jobtype::Find($newtask_jobid);
  57. UpdateTaskType($newtask_jobtype, $taskvalue, $index, $oldtype);
  58. }
  59. else if ($new == "4")
  60. {
  61. //add new tasktype to jobtype!
  62. AddTaskType($new_task_jobid, $new_tasktype_id, $tasktypesarr);
  63. }
  64. $alltasktypes = GrabTasktypes("subs");
  65. $str = "<option value='deletetasktype'>----Очистить тип----</option>";
  66. foreach ($alltasktypes as $type)
  67. {
  68. $str .= "<option id='opt_$type->id' value='" . $type->id . "'> $type->name [$type->id]</option>";
  69. }
  70. echo "<div id='alltasktypescont' style='display: none'><select id='alltasktypes'>$str</select></div>";
  71. echo "<h3>Должности компании ".$companyname.":</h3>
  72. <form id='form1' name='form1' method='post'>";
  73. $str = "select j.id, t.company, j.name, t.id as tid, t.name as tname from jobtypes_tasktypes jt join tasktypes t on jt.tasktype_id=t.id RIGHT JOIN jobtypes j on jt.jobtype_id = j.id where j.company=".$companyID;
  74. $query = mysqli_query($link, $str);
  75. for ($myarr = array(); $res = mysqli_fetch_object($query); $myarr[] = $res);
  76. $jobids = array();
  77. echo "<div id='result'></div>";
  78. foreach ($myarr as $jobtype)
  79. {
  80. $job_id = $jobtype->id;
  81. if ($jobtype->company && $jobtype->company != $companyID)
  82. continue;
  83. //Tasktype::ConvertTasktypes($jobtype);
  84. $jobname = $jobtype->name;
  85. $tasktypes = (object) [
  86. 'id' => $jobtype->tid,
  87. 'name' => $jobtype->tname,
  88. 'jobname' => $jobtype->name,
  89. ];
  90. $jobids[$job_id][] = $tasktypes;
  91. }
  92. $alltasktypes = GrabTasktypes("subs"); //массив id
  93. foreach ($jobids as $job_id=>$tasktypes) {
  94. echo "<div id='jobid_$job_id' class='border'>";
  95. echo "<h4>" . $tasktypes[0]->jobname . " [$job_id]</h4>";
  96. EchoTasks2($job_id, $tasktypes, $alltasktypes); //селект со списком типов команд для данной должности
  97. $projecttypes = array();
  98. $ptids = array();
  99. $ptstring = '';
  100. foreach ($tasktypes as $ttype) {
  101. $parents = FindParentTaskType($ttype->id);
  102. foreach ($parents as $parent) {
  103. $mytt = Tasktype::Find($parent['id']);
  104. $myprojecttypes = FindActions($parent['id']);
  105. foreach ($mytt->getProjecttypes() as $pt) {
  106. if (!$ptids[$pt->id]) {
  107. $ptids[$pt->id] = 1;
  108. $ptstring .= "<br>[$pt->id. $pt->name] ";
  109. }
  110. }
  111. }
  112. }
  113. echo "<br><b>Доступные типы проектов:</b> $ptstring<br>";
  114. echo "<br><b>Доступные типы задач</b><br>";
  115. echo "<br><input type='button' onclick='EditJobs(this, $job_id)' value='Редактировать'>";
  116. echo "<br><input type='button' onclick='ShowTaskTypes($job_id, \"$tasktypes\")' value='Добавить команду'>";
  117. echo " <input type='button' onclick='DelJob($job_id)' value='Удалить'>";
  118. echo "</div>";
  119. echo "<br>";
  120. }
  121. echo "</form>";
  122. echo "
  123. <form id='form2' name='form2' method='post'>
  124. <input type='submit' value='Добавить новую должность'>
  125. <input type='hidden' name='new' value='1'>
  126. </form>
  127. ";
  128. echo '
  129. <style type="text/css">
  130. .border {
  131. border: 1px solid #9cb2c4;
  132. border-radius: 15px;
  133. overflow: hidden;
  134. margin:5px;
  135. padding: 15px;
  136. }
  137. </style>
  138. ';
  139. EchoEdit();
  140. }
  141. function EchoTasks2($job_id, $tasktypes, $alltasktypes)
  142. {
  143. $account_jobindex = 0; //
  144. $index = 0;
  145. foreach ($tasktypes as $tasktype)
  146. {
  147. echo " <select class='selectdiv' disabled id='jobs_".$job_id."_".$index."' onchange='if (!ChangeTaskType(".$job_id.", this.value, $account_jobindex, $tasktype->id)) this.form.reset();'>";
  148. echo "<option value='deletetasktype'>----Очистить тип----</option>";
  149. foreach ($alltasktypes as $type) {
  150. $sel = "";
  151. if ($tasktype->id == $type->id) {
  152. $sel = "selected";
  153. echo "<option " . $sel . " value='" . $type->id . "'>" . $type->id . ". " . $type->name . "</option>";
  154. }
  155. }
  156. $index++;
  157. echo "</select><br>";
  158. $account_jobindex++;
  159. }
  160. }
  161. //селект со списком типов команд для данной должности
  162. function EchoTasks($jobtype)
  163. {
  164. $account_jobindex = 0; //
  165. $jobtasktypes = $jobtype->getTaskTypes();
  166. $alltasktypes = GrabTasktypes("subs"); //массив id
  167. $job_id = $jobtype->id;
  168. foreach ($jobtasktypes as $tasktype)
  169. {
  170. echo " <select id='jobs' name='jobs' onchange='if (!ChangeTaskType(".$job_id.", this.value, $account_jobindex, $tasktype->id)) this.form.reset();'>";
  171. echo "<option value='deletetasktype'>----Очистить тип----</option>";
  172. foreach ($alltasktypes as $type) {
  173. $sel = "";
  174. if ($tasktype->id == $type->id)
  175. $sel = "selected";
  176. echo "<option ".$sel." value='" . $type->id . "'>" . $type->id.". ".$type->name . "</option>";
  177. }
  178. echo "</select>";
  179. $account_jobindex++;
  180. }
  181. }
  182. function UpdateTaskType(Jobtype $newtask_jobtype, $taskvalue, $jobindex, $oldtype)
  183. {
  184. $tasks = $newtask_jobtype->getTaskTypes();
  185. $oldtask = Tasktype::Find($oldtype);
  186. $tasks->removeElement($oldtask);
  187. if ($taskvalue != 'deletetasktype') {
  188. $newtasktype = Tasktype::Find($taskvalue);
  189. $newtask_jobtype->addTasktype($newtasktype);
  190. $newtasktype->Save();
  191. }
  192. $newtask_jobtype->Save();
  193. }
  194. function AddTaskType($job_id, $new_tasktype_id, $tasktypes)
  195. {
  196. //$new_task_jobid - должность
  197. //$new_tasktype_id - тип задачи
  198. $newtasktype = Tasktype::Find($new_tasktype_id);
  199. $jobtype = Jobtype::Find($job_id);
  200. $jobtype->addTasktype($newtasktype);
  201. $jobtype->Save();
  202. global $link;
  203. //echo "AddJob ".$acc_id." job id ".$new_jobtype_id." job_ids ".$job_ids;
  204. $tasktypes .= ','.$new_tasktype_id;
  205. mysqli_query($link, "update jobtypes set tasktypes='".$tasktypes."' where id=".$job_id);
  206. echo "<span style='color: darkolivegreen'>Команда добавлена!</span><br><br>";
  207. }
  208. function EchoEdit()//, $job_ids_account)
  209. {
  210. $alltasktypes = GrabTasktypes("subs"); //массив id
  211. echo "<div id='tasks_block' style=\"display: none; margin-left: 0px; padding: 10px; background-color: white; border-color: #E1E1E1; border: solid; border-width: 1px; position: fixed; top: 100px;left: 300px \">";
  212. echo "<span style='color: green'><b>Выберите добавляемую команду:</b></span>";
  213. echo "<form id='form3' name='form3' method='post'>";
  214. echo " <select name='new_tasktype_id'>";
  215. foreach ($alltasktypes as $tasktype)
  216. {
  217. echo "<option value='" . $tasktype->id . "'>" . $tasktype->name . "</option>";
  218. //echo 'jobtype '.$jobtype['name'];
  219. }
  220. echo "</select>";
  221. echo "<input type='submit' value='Добавить'>
  222. <input type='hidden' name='new' value='4'>
  223. <input type='hidden' name='new_task_jobid' value=''>
  224. <input type='hidden' name='tasktypes' value=''>";
  225. echo "</form></div><br>";
  226. }
  227. ?>