fluxdWatchSettings.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. /* $Id: fluxdWatchSettings.php 2981 2007-05-11 21:54:43Z warion $ */
  3. /*******************************************************************************
  4. LICENSE
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License (GPL)
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  14. *******************************************************************************/
  15. // prevent direct invocation
  16. if ((!isset($cfg['user'])) || (isset($_REQUEST['cfg']))) {
  17. @ob_end_clean();
  18. @header("location: ../../../index.php");
  19. exit();
  20. }
  21. /******************************************************************************/
  22. // Watch
  23. FluxdServiceMod::initializeServiceMod('Watch');
  24. // init template-instance
  25. tmplInitializeInstance($cfg["theme"], "page.admin.fluxdWatchSettings.tmpl");
  26. // message section
  27. $message = tfb_getRequestVar('m');
  28. if ((isset($message)) && ($message != "")) {
  29. $tmpl->setvar('new_msg', 1);
  30. $tmpl->setvar('message', urldecode($message));
  31. } else {
  32. $tmpl->setvar('new_msg', 0);
  33. }
  34. // pageop
  35. //
  36. // * default
  37. //
  38. // * addJob
  39. // * editJob
  40. // * saveJob
  41. // * deleteJob
  42. //
  43. $with_profiles = $cfg['transfer_profiles'] >= 1 ? 1 : 0;
  44. $tmpl->setvar('with_profiles', $with_profiles);
  45. $wasWatchError = false;
  46. function setWatchError($msg) {
  47. global $tmpl, $wasWatchError;
  48. $wasWatchError = true;
  49. $tmpl->setvar('new_msg', 1);
  50. $tmpl->setvar('message', $msg);
  51. }
  52. $pageop = tfb_getRequestVar('pageop');
  53. $pageop2 = $pageop = (empty($pageop)) ? "default" : $pageop;
  54. $tmpl->setvar('pageop', $pageop);
  55. // op-switch
  56. switch ($pageop) {
  57. default:
  58. case "default":
  59. // jobs
  60. $jobs = FluxdWatch::jobsGetList();
  61. if ($jobs === false)
  62. setWatchError('Error : could not load jobs.');
  63. else
  64. $tmpl->setloop('watch_jobs', $jobs);
  65. // title-bar
  66. tmplSetTitleBar("Administration - Fluxd Watch Settings");
  67. break;
  68. case "addJob":
  69. case "editJob":
  70. case "saveJob":
  71. $jobNumber = trim(tfb_getRequestVarRaw('job'));
  72. $isNew = empty($jobNumber);
  73. $watchdir = trim(tfb_getRequestVarRaw('watchdir'));
  74. $user = trim(tfb_getRequestVarRaw('user'));
  75. $profile = trim(tfb_getRequestVarRaw('profile'));
  76. $checkdir = trim(tfb_getRequestVarRaw('checkdir'));
  77. $postback = tfb_getRequestVarRaw('postback');
  78. $isPostback = $postback == '1';
  79. $refresh = tfb_getRequestVarRaw('refresh');
  80. $isRefresh = $refresh == '1';
  81. $isSave = $isPostback && !$isRefresh;
  82. $checkdir = ($checkdir == '1' || $checkdir == 'on' || $checkdir == 'true');
  83. if ($isSave) { // saving (a new one or an existing one)
  84. $pageop2 = "saveJob";
  85. $paramErrors = 0;
  86. if (strlen($watchdir) == 0)
  87. $paramErrors++;
  88. if (strlen($user) == 0)
  89. $paramErrors++;
  90. if ($paramErrors != 0)
  91. setWatchError('Error : Argument-Error.');
  92. else {
  93. if ($isNew) {
  94. $result = FluxdWatch::jobAdd($watchdir, $user, $profile, $checkdir);
  95. if ($result !== false)
  96. $tmpl->setvar('watch_job_message', 'Job added.');
  97. } else {
  98. $result = FluxdWatch::jobUpdate($jobNumber, $watchdir, $user, $profile, $checkdir);
  99. if ($result !== false)
  100. $tmpl->setvar('watch_job_message', 'Job updated.');
  101. }
  102. if ($result === false) {
  103. $wasWatchError = true;
  104. $messages = array();
  105. $msgs = FluxdWatch::getMessages();
  106. foreach ($msgs as $msg)
  107. array_push($messages, array('msg' => $msg));
  108. $tmpl->setloop('messages', $messages);
  109. }
  110. }
  111. $tmpl->setvar('watch_job_saved', !$wasWatchError);
  112. // title-bar
  113. tmplSetTitleBar("Administration - Fluxd Watch - Save Job");
  114. } else { // initial display, or refresh (of a new one or of an existing one)
  115. $pageop2 = "addJobOReditJob";
  116. // job number
  117. $tmpl->setvar('jobnumber', $jobNumber);
  118. // initial display of an existing job: load its contents
  119. if (!$isNew && !$isRefresh) {
  120. $job = FluxdWatch::jobGetContent($jobNumber);
  121. if ($job === false)
  122. $wasWatchError = true;
  123. else {
  124. $watchdir = $job['D'];
  125. $user = $job['U'];
  126. $profile = isset($job['P']) ? $job['P'] : '';
  127. }
  128. }
  129. if (!$wasWatchError) {
  130. // job number
  131. $tmpl->setvar('jobnumber', $jobNumber);
  132. // watchdir
  133. $tmpl->setvar('watchdir', $watchdir);
  134. // users
  135. $watchusers = array();
  136. $userCount = count($cfg['users']);
  137. $foundSel = false;
  138. for ($i = 0; $i < $userCount; $i++) {
  139. $tmp = $cfg['users'][$i];
  140. $sel = ((!$isNew || $isRefresh) && $user == $tmp) ? 1 : 0;
  141. if ($sel)
  142. $foundSel = true;
  143. array_push($watchusers, array(
  144. 'name' => $tmp,
  145. 'is_selected' => $sel
  146. ));
  147. }
  148. if (!$foundSel) {
  149. // no or invalid user, just set superadmin by default
  150. $user = GetSuperAdmin();
  151. foreach ($watchusers as $k => $watchuser)
  152. if ($user == $watchuser['name'])
  153. $watchusers[$k]['is_selected'] = 1;
  154. }
  155. $tmpl->setloop('watch_users', $watchusers);
  156. // profiles
  157. if ($with_profiles) {
  158. $profiles = GetProfilesByUserName($user, $profile);
  159. $public_profiles = GetPublicProfiles($profile);
  160. $tmpl->setloop('profiles', $profiles);
  161. $tmpl->setloop('public_profiles', $public_profiles);
  162. }
  163. // checkdir
  164. $tmpl->setvar('checkdir', (!$isRefresh || $checkdir) ? 1 : 0);
  165. }
  166. $tmpl->setvar('watch_job_loaded', !$wasWatchError);
  167. // title-bar
  168. tmplSetTitleBar("Administration - Fluxd Watch - ".($isNew ? "Add" : "Edit")." Job");
  169. }
  170. break;
  171. case "deleteJob":
  172. $jobNumber = trim(tfb_getRequestVar('job'));
  173. if (empty($jobNumber)) {
  174. setWatchError('Error : No Job-Number.');
  175. $tmpl->setvar('watch_job_deleted', 0);
  176. } else {
  177. $tmpl->setvar('watch_job_deleted', (FluxdWatch::jobDelete($jobNumber) === true) ? 1 : 0);
  178. }
  179. // title-bar
  180. tmplSetTitleBar("Administration - Fluxd Watch - Delete Job");
  181. break;
  182. }
  183. $tmpl->setvar('pageop2', $pageop2);
  184. //
  185. $tmpl->setvar('enable_dereferrer', $cfg["enable_dereferrer"]);
  186. //
  187. tmplSetAdminMenu();
  188. tmplSetFoot();
  189. tmplSetIidVars();
  190. // parse template
  191. $tmpl->pparse();
  192. ?>