Advertisement
Guest User

Untitled

a guest
Nov 10th, 2011
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 449.25 KB | None | 0 0
  1. Use CONNECT or CREATE DATABASE to specify a database
  2. CONNECT "/var/Motiw/db/motiw.fdb" USER 'SYSDBA' PASSWORD 'masterkey';
  3.  
  4. SET NAMES WIN1251;
  5.  
  6. update patch_info
  7. set paramvalue = 'Updates to 1.4.18'
  8. where paramname = 'PATCH_STATUS';
  9. update patch_info
  10. set paramvalue = cast(paramvalue as integer) + 1
  11. where paramname = 'PATCH_STEP';
  12. SET GENERATOR gen_patch_percent to 0;
  13. COMMIT WORK;
  14. /*-----------------------------------------------------------------------------------------------------------------------*/
  15. /* Ну и по традиции тут удаляем хлам и пережитки прошлой жизни */
  16. /*-----------------------------------------------------------------------------------------------------------------------*/
  17. SET TERM ^ ;
  18. CREATE OR ALTER PROCEDURE TMP_DROP_XLAM
  19. AS
  20. declare variable is_exist smallint;
  21. BEGIN
  22. SELECT result FROM IS_PROCEDURE_EXISTS('GETPERMREE_FOR_EMPLOYER_DOCINIT')
  23. INTO :is_exist;
  24.  
  25. IF (is_exist = 1) THEN
  26. begin
  27. EXECUTE STATEMENT
  28. 'DROP PROCEDURE GETPERMREE_FOR_EMPLOYER_DOCINIT;';
  29. end
  30.  
  31. SELECT result FROM IS_PROCEDURE_EXISTS('GETOPENTASKSFORREPORT4')
  32. INTO :is_exist;
  33.  
  34. IF (is_exist = 1) THEN
  35. begin
  36. EXECUTE STATEMENT
  37. 'DROP PROCEDURE GETOPENTASKSFORREPORT4;';
  38. end
  39.  
  40. SELECT result FROM IS_PROCEDURE_EXISTS('GETALLNOTICES')
  41. INTO :is_exist;
  42.  
  43. IF (is_exist = 1) THEN
  44. begin
  45. EXECUTE STATEMENT
  46. 'DROP PROCEDURE GETALLNOTICES;';
  47. end
  48. END ^
  49. SET TERM ; ^
  50. commit;
  51.  
  52. EXECUTE PROCEDURE TMP_DROP_XLAM;
  53. commit;
  54. DROP PROCEDURE TMP_DROP_XLAM;
  55. commit;
  56.  
  57. /* добавляем шаблон задачи по умолчанию */
  58. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('EMPLOYER', 'TASK_TEMPLATE_DEFAULT', 'INTEGER');
  59.  
  60. RESULT
  61. =======
  62. 1
  63.  
  64. commit;
  65.  
  66. /* право на создание задач (для проверки доступности кнопки создания задачи) */
  67. update menuitems set right_kind = 23
  68. where item_id = 101;
  69. commit;
  70.  
  71. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('EMPLOYER', 'CAN_ADD_TASK', 'SMALLINT');
  72.  
  73. RESULT
  74. =======
  75. 1
  76.  
  77. commit;
  78.  
  79. update employer set can_add_task = 1
  80. where can_add_task is null;
  81. commit;
  82.  
  83. /*---------------------------------------------------------------------------------------*/
  84. /* stasy: Группы пользователей*/
  85. /*---------------------------------------------------------------------------------------*/
  86. /* Создаем таблицу EMP_GROUPS */
  87. SET TERM ^ ;
  88. CREATE OR ALTER PROCEDURE TMP_EMP_GROUPS_CREATE
  89. AS
  90. declare variable is_exist smallint;
  91. BEGIN
  92. /* Гарантируем генератор */
  93. SELECT result FROM IS_GENERATOR_EXISTS('GEN_EMP_GROUPS_ID')
  94. INTO :is_exist;
  95.  
  96. IF (is_exist = 0) THEN
  97. BEGIN
  98. EXECUTE STATEMENT
  99. 'CREATE GENERATOR GEN_EMP_GROUPS_ID';
  100. END
  101.  
  102. /* Гарантируем таблицу */
  103. SELECT result FROM IS_TABLE_EXISTS('EMP_GROUPS')
  104. INTO :is_exist;
  105.  
  106. IF (is_exist = 0) THEN
  107. BEGIN
  108. EXECUTE STATEMENT
  109. 'CREATE TABLE EMP_GROUPS (
  110. ID_GROUP INTEGER NOT NULL,
  111. TITLE VARCHAR(200) NOT NULL,
  112. DISCRIPTION VARCHAR(1000),
  113. IS_DELITED SMALLINT,
  114. ID_OWNER INTEGER NOT NULL,
  115. iscommon SMALLINT,
  116. constraint PK_EMP_GROUPS_ID primary key (ID_GROUP))';
  117. END
  118. END ^
  119. SET TERM ; ^
  120. commit;
  121. EXECUTE PROCEDURE TMP_EMP_GROUPS_CREATE;
  122. commit;
  123. DROP PROCEDURE TMP_EMP_GROUPS_CREATE;
  124. commit;
  125.  
  126. /* Создаем триггер для генерации ID */
  127. SET TERM ^;
  128. CREATE OR ALTER TRIGGER EMP_GROUPS_BI_GEN_ID
  129. FOR EMP_GROUPS
  130. ACTIVE BEFORE INSERT
  131. AS
  132. BEGIN
  133. IF (NEW.ID_GROUP IS NULL) THEN
  134. NEW.ID_GROUP = GEN_ID(GEN_EMP_GROUPS_ID, 1);
  135. END^
  136. SET TERM ; ^
  137. commit;
  138.  
  139. /* раздаем гранты на таблицу */
  140. EXECUTE PROCEDURE GIVE_GRANTS_TO_ALL('TABLE','EMP_GROUPS','ALL');
  141. commit;
  142.  
  143. /* Таблица EMPLOUEROFGROUP */
  144.  
  145. /* Создаем таблицу EMPLOUEROFGROUP для связки таблиц EMP_GROUPS и employer (пользователь может находиться в нескольких группах) */
  146. SET TERM ^ ;
  147. CREATE OR ALTER PROCEDURE TMP_EMPLOYEROFGROUP_CREATE
  148. AS
  149. declare variable is_exist smallint;
  150. BEGIN
  151. /* Гарантируем таблицу */
  152. SELECT result FROM IS_TABLE_EXISTS('EMPLOYEROFGROUP')
  153. INTO :is_exist;
  154.  
  155. IF (is_exist = 0) THEN
  156. BEGIN
  157. EXECUTE STATEMENT
  158. 'CREATE TABLE EMPLOYEROFGROUP (
  159. ID_EMP INTEGER NOT NULL,
  160. ID_GROUP INTEGER NOT NULL,
  161. PERMITION SMALLINT,
  162. IS_DELITED SMALLINT,
  163. constraint PK_EMPLOYEROFGROUP primary key (ID_EMP, ID_GROUP))';
  164. END
  165. END ^
  166. SET TERM ; ^
  167. commit;
  168. EXECUTE PROCEDURE TMP_EMPLOYEROFGROUP_CREATE;
  169. commit;
  170. DROP PROCEDURE TMP_EMPLOYEROFGROUP_CREATE;
  171. commit;
  172.  
  173. /* раздаем гранты на таблицу */
  174. EXECUTE PROCEDURE GIVE_GRANTS_TO_ALL('TABLE','EMPLOYEROFGROUP','ALL');
  175. commit;
  176.  
  177. /*создаем пункт меню группы пользователей*/
  178.  
  179. EXECUTE PROCEDURE ADDMENUITEMBYTAG(868, 'L_GLOBAL_PERMISSIONS_GROUP', '/user/empgroup/', 'L_MENU_ADMINISTRATION', 8, 1, 6, NULL);
  180. commit;
  181.  
  182. /*добавляем право на группы пользователей*/
  183.  
  184. SET TERM ^ ;
  185.  
  186. CREATE OR ALTER PROCEDURE GET_RIGHTS_OF_GROUP (
  187. i_id_employer integer,
  188. i_id_groupright integer)
  189. returns (
  190. o_right_kind integer,
  191. o_id_object integer,
  192. o_objectname varchar(1000),
  193. o_group_has_right smallint,
  194. o_can_edit smallint)
  195. as
  196. declare variable l_id_owner integer;
  197. declare variable l_id_groupright integer;
  198. begin
  199.  
  200. O_ID_OBJECT = 0;
  201. O_OBJECTNAME = '';
  202. for select gl.id
  203. from grouprights_list gl
  204. into :O_RIGHT_KIND
  205. do
  206. begin
  207. select o_result from get_right_employer_and_group(:i_id_employer,:o_right_kind,0)
  208. into :o_can_edit;
  209.  
  210. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  211. into :o_group_has_right;
  212. suspend;
  213. end
  214.  
  215. for select dt.id, dt.name, dt.id_owner from doctypes dt
  216. where dt.isdeleted=0
  217. into :o_id_object, :o_objectname, :l_id_owner
  218. do
  219. begin
  220. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  221. o_can_edit = 1;
  222. else
  223. o_can_edit = 0;
  224. o_right_kind = 1;
  225. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  226. into :o_group_has_right;
  227. suspend;
  228. o_right_kind = 2;
  229. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  230. into :o_group_has_right;
  231. suspend;
  232. o_right_kind = 28; /* 28 - право выбора связанных документов */
  233. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  234. into :o_group_has_right;
  235. suspend;
  236. end
  237.  
  238. o_right_kind = 3;
  239. for select rt.id, rt.name, rt.id_owner from routetemplate rt
  240. where rt.isdeleted=0 and rt.kind=0
  241. into :o_id_object, :o_objectname, :l_id_owner
  242. do
  243. begin
  244. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  245. o_can_edit = 1;
  246. else
  247. o_can_edit = 0;
  248. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  249. into :o_group_has_right;
  250. suspend;
  251. end
  252.  
  253. o_right_kind = 9;
  254. for select fd.id, fd.name, fd.id_owner from fdoctemplate fd
  255. where fd.isdeleted=0
  256. into :o_id_object, :o_objectname, :l_id_owner
  257. do
  258. begin
  259. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  260. o_can_edit = 1;
  261. else
  262. o_can_edit = 0;
  263. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  264. into :o_group_has_right;
  265. suspend;
  266. end
  267.  
  268. o_right_kind = 12;
  269. for select it.id, it.name, it.id_owner from iwgtemplate it
  270. where it.isdeleted=0
  271. into :o_id_object, :o_objectname, :l_id_owner
  272. do
  273. begin
  274. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  275. o_can_edit = 1;
  276. else
  277. o_can_edit = 0;
  278. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  279. into :o_group_has_right;
  280. suspend;
  281. end
  282.  
  283. o_right_kind = 10;
  284. if (I_ID_GROUPRIGHT is null) then L_ID_GROUPRIGHT=0;
  285. else
  286. L_ID_GROUPRIGHT=:I_ID_GROUPRIGHT;
  287. for select g.id, g.name, g.id_owner from grouprights g
  288. where g.isdeleted=0 and g.isvisible=1 and g.id<>:L_ID_GROUPRIGHT
  289. into :o_id_object, :o_objectname, :l_id_owner
  290. do
  291. begin
  292. if (l_id_owner=i_id_employer ) then
  293. o_can_edit = 1;
  294. else
  295. o_can_edit = 0;
  296. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  297. into :o_group_has_right;
  298. suspend;
  299. end
  300. o_right_kind = 15;
  301. o_can_edit = 1;
  302. for select md.id, md.name, md.id_owner
  303. from meta_dictionary md
  304. where md.isdeleted=0 and md.id_owner=:i_id_employer and recordtype=1
  305. into :o_id_object, :o_objectname, :l_id_owner
  306. do
  307. begin
  308. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  309. into :o_group_has_right;
  310. suspend;
  311. end
  312. /* 17 права на просмотр записей в справочнике */
  313. /* 18 права на добавление записей в справочник */
  314. /* 19 права на изменение записей в справочнике */
  315. /* 20 права на удаление записей в справочнике */
  316. o_can_edit = 1;
  317. for select md.id, md.name, md.id_owner
  318. from meta_dictionary md
  319. where md.isdeleted=0 and md.id_owner=:i_id_employer and recordtype=0
  320. into :o_id_object, :o_objectname, :l_id_owner
  321. do
  322. begin
  323. o_right_kind = 17;
  324. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  325. into :o_group_has_right;
  326. suspend;
  327. o_right_kind = 18;
  328. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  329. into :o_group_has_right;
  330. suspend;
  331. o_right_kind = 19;
  332. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  333. into :o_group_has_right;
  334. suspend;
  335. o_right_kind = 20;
  336. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  337. into :o_group_has_right;
  338. suspend;
  339. end
  340. o_right_kind = 22;
  341. for select tt.id, tt.name, tt.id_owner from task_templates tt
  342. into :o_id_object, :o_objectname, :l_id_owner
  343. do
  344. begin
  345. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  346. o_can_edit = 1;
  347. else
  348. o_can_edit = 0;
  349. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  350. into :o_group_has_right;
  351. suspend;
  352. end
  353. -- плагины не привязвнные к типам
  354. o_right_kind = 77;
  355. for select plg.id, plg.name, plg.id_owner from plugins plg where plg.no_connect_to_type=1
  356. into :o_id_object, :o_objectname, :l_id_owner
  357. do
  358. begin
  359. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  360. o_can_edit = 1;
  361. else
  362. o_can_edit = 0;
  363. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  364. into :o_group_has_right;
  365. suspend;
  366. end
  367. /* 23 права на просмотр событий календаря */
  368. /* 24 права на добавление и редактирование событий в календарь */
  369. /* 25 полные права*/
  370. o_can_edit = 1;
  371. for select c.id, c.name, c.id_owner
  372. from calendars c
  373. where c.id_owner=:i_id_employer and is_system=0
  374. into :o_id_object, :o_objectname, :l_id_owner
  375. do
  376. begin
  377. o_right_kind = 23;
  378. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  379. into :o_group_has_right;
  380. suspend;
  381. o_right_kind = 24;
  382. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  383. into :o_group_has_right;
  384. suspend;
  385. o_right_kind = 25;
  386. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  387. into :o_group_has_right;
  388. suspend;
  389. end
  390. o_right_kind = 26;
  391. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,0)
  392. into :o_group_has_right;
  393. suspend;
  394.  
  395. /* 27 права на общедоступные группы внешних пользователей */
  396. for select eeg.id, eeg.name, eeg.id_owner from email_employer_group eeg
  397. where eeg.isdeleted=0 and eeg.iscommon=1
  398. into :o_id_object, :o_objectname, :l_id_owner
  399. do
  400. begin
  401. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  402. o_can_edit = 1;
  403. else
  404. o_can_edit = 0;
  405. o_right_kind = 27;
  406. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  407. into :o_group_has_right;
  408. suspend;
  409. end
  410.  
  411. /* 29 - права на группы пользователей*/
  412.  
  413. for select eeg.id_group, eeg.title, eeg.id_owner from EMP_GROUPS eeg
  414. where eeg.IS_DELITED=0
  415. into :o_id_object, :o_objectname, :l_id_owner
  416. do
  417. begin
  418. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  419. o_can_edit = 1;
  420. else
  421. o_can_edit = 0;
  422. o_right_kind = 29;
  423. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  424. into :o_group_has_right;
  425. suspend;
  426.  
  427. end
  428.  
  429. end^
  430.  
  431. SET TERM ; ^
  432. COMMIT;
  433.  
  434. /*процедура возвращает системные права пользователей - так, как если бы он создавался
  435. ** сотрудник - полное право на себя
  436. ** начальник - полное право на свой отдел и подчиненные
  437. ** - только свои задачи на начальников и делопроизводителей одного уровня
  438. ** делопроиз - только свои задачи на свой отдел и подчиненные
  439. ** - начальников и делопроизводителей одного уровня*/
  440.  
  441. SET TERM ^ ;
  442.  
  443. CREATE OR ALTER PROCEDURE GET_SISTEM_PERM (
  444. i_id integer)
  445. returns (
  446. o_emp integer,
  447. o_right integer)
  448. as
  449. declare variable l_boss integer;
  450. declare variable l_depid integer;
  451. declare variable l_empid integer;
  452. declare variable l_isboss integer;
  453. declare variable l_mydepid integer;
  454. declare variable l_myparentdepid integer;
  455. declare variable l_parentdepid integer;
  456. BEGIN
  457. /*проверяем кем является чувак и выбираем его подразделение*/
  458. select e.isboss, e.id_department from employer e where e.id = :i_id
  459. into :l_boss, :L_MYDEPID;
  460. if (:l_boss = 0) then exit;/*если просто сотрудник - то выходим*/
  461. /*получаем родительское подразделение*/
  462. select parentid from department
  463. where id = :L_MYDEPID
  464. into :L_MYPARENTDEPID;
  465. /*получаем подразделение "для начальника"*/
  466. for select O_ID
  467. from GETTREE_FOR_BOSS (:i_id)
  468. into :L_DEPID
  469. do
  470. begin
  471. /*находим подразделения одного уровня*/
  472. select parentid
  473. from department
  474. where id=:L_DEPID
  475. into :L_PARENTDEPID;
  476. /*и проверяем там каждого сотрудника*/
  477. for select id, isboss
  478. from employer
  479. where isdeleted = 0 and
  480. id_department = :L_DEPID
  481. into :o_emp, :L_ISBOSS
  482. do
  483. begin /*если оного уровня, но не свое подразделения*/
  484. if ((:L_MYPARENTDEPID = :L_PARENTDEPID) and
  485. (:L_ISBOSS > 0) and
  486. (:L_DEPID <> :L_MYDEPID)) then
  487. begin/*тогда только свои задачи для начальников*/
  488. o_right = 2;
  489. suspend;
  490. end
  491.  
  492. else /*если свое подразделение*/
  493. begin
  494. if ((:L_MYPARENTDEPID <> :L_PARENTDEPID) or (:L_DEPID = :L_MYDEPID) ) then
  495. begin
  496. if (:l_boss = 1) then
  497. begin
  498. o_right = 1;
  499. suspend;
  500. end
  501. else
  502. begin
  503. o_right = 2;
  504. suspend;
  505. end
  506. end
  507. end
  508. end
  509.  
  510. end
  511. END^
  512.  
  513. SET TERM ; ^
  514. COMMIT;
  515.  
  516. /*---------------------------------------------------------------------------------------*/
  517. /* stasy: Группы пользователей - конец*/
  518. /*---------------------------------------------------------------------------------------*/
  519. /*---------------------------------------------------------------------------------------*/
  520. /* stasy: Задания по событиям - начало*/
  521. /*---------------------------------------------------------------------------------------*/
  522. /* 1.1 Создаем таблицу EVENTS_TYPES, в ней будет id события и тег */
  523. /*---------------------------------------------------------------------------------------*/
  524. SET TERM ^ ;
  525. CREATE OR ALTER PROCEDURE TMP_JOBS_TYPES_CREATE
  526. AS
  527. declare variable is_exist smallint;
  528. BEGIN
  529. /* Гарантируем таблицу */
  530. SELECT result FROM IS_TABLE_EXISTS('JOBS_TYPES')
  531. INTO :is_exist;
  532.  
  533. IF (is_exist = 0) THEN
  534. BEGIN
  535. EXECUTE STATEMENT
  536. 'CREATE TABLE JOBS_TYPES (
  537. ID_TYPE INTEGER NOT NULL,
  538. TYPE_NAME VARCHAR(200) NOT NULL,
  539. constraint PK_JOBS_TYPES primary key (ID_TYPE))';
  540. END
  541. END ^
  542. SET TERM ; ^
  543. commit;
  544. EXECUTE PROCEDURE TMP_JOBS_TYPES_CREATE;
  545. commit;
  546. DROP PROCEDURE TMP_JOBS_TYPES_CREATE;
  547. commit;
  548. /*---------------------------------------------------------------------------------------*/
  549. /* 1.2 раздаем гранты на таблицу */
  550. /*---------------------------------------------------------------------------------------*/
  551. EXECUTE PROCEDURE GIVE_GRANTS_TO_ALL('TABLE','JOBS_TYPES','ALL');
  552. commit;
  553. /*---------------------------------------------------------------------------------------*/
  554. /* 1.3 к этому моменту в ней будет одно значение - "создать подзадачу по шаблону"*/
  555. /*---------------------------------------------------------------------------------------*/
  556. SET TERM ^ ;
  557. CREATE OR ALTER PROCEDURE TMP_JOBS_TYPES_INSERT
  558. AS
  559. declare variable is_exist smallint;
  560. BEGIN
  561. /*если еще пустая*/
  562. SELECT count(*) from JOBS_TYPES
  563. INTO :is_exist;
  564.  
  565. IF (is_exist = 0) THEN
  566. BEGIN
  567. INSERT INTO JOBS_TYPES (ID_TYPE, TYPE_NAME) VALUES (1, 'L_SUB_TASK_BY_TEMPL');
  568. END
  569. END ^
  570. SET TERM ; ^
  571. commit;
  572. EXECUTE PROCEDURE TMP_JOBS_TYPES_INSERT;
  573. commit;
  574. DROP PROCEDURE TMP_JOBS_TYPES_INSERT;
  575. commit;
  576.  
  577. /*---------------------------------------------------------------------------------------*/
  578. /* 2.1 Создаем таблицу jobs, в ней будет: локальный id, тип задания и ид задания */
  579. /*---------------------------------------------------------------------------------------*/
  580. SET TERM ^ ;
  581. CREATE OR ALTER PROCEDURE TMP_JOBS_CREATE
  582. AS
  583. declare variable is_exist smallint;
  584. BEGIN
  585.  
  586. /* Гарантируем генератор */
  587. SELECT result FROM IS_GENERATOR_EXISTS('GEN_JOB_ID')
  588. INTO :is_exist;
  589.  
  590. IF (is_exist = 0) THEN
  591. BEGIN
  592. EXECUTE STATEMENT
  593. 'CREATE GENERATOR GEN_JOB_ID';
  594. END
  595.  
  596. /* Гарантируем таблицу */
  597. SELECT result FROM IS_TABLE_EXISTS('JOBS')
  598. INTO :is_exist;
  599.  
  600. IF (is_exist = 0) THEN
  601. BEGIN
  602. EXECUTE STATEMENT
  603. 'CREATE TABLE JOBS (
  604. ID_JOB_LIST INTEGER,
  605. ID_JOB INTEGER NOT NULL,
  606. ID_JOB_TYPE INTEGER NOT NULL,
  607. constraint PK_JOBS primary key (ID_JOB))';
  608. END
  609. END ^
  610. SET TERM ; ^
  611. commit;
  612. EXECUTE PROCEDURE TMP_JOBS_CREATE;
  613. commit;
  614. DROP PROCEDURE TMP_JOBS_CREATE;
  615. commit;
  616. /*---------------------------------------------------------------------------------------*/
  617. /* 2.2 Создаем триггер для генерации ID */
  618. /*---------------------------------------------------------------------------------------*/
  619. SET TERM ^;
  620. CREATE OR ALTER TRIGGER JOB_BI_GEN_ID
  621. FOR JOBS
  622. ACTIVE BEFORE INSERT
  623. AS
  624. BEGIN
  625. IF (NEW.ID_JOB IS NULL) THEN
  626. NEW.ID_JOB = GEN_ID(GEN_JOB_ID, 1);
  627. END^
  628. SET TERM ; ^
  629. commit;
  630. /*---------------------------------------------------------------------------------------*/
  631. /* 2.3 раздаем гранты на таблицу */
  632. /*---------------------------------------------------------------------------------------*/
  633. EXECUTE PROCEDURE GIVE_GRANTS_TO_ALL('TABLE','JOBS','ALL');
  634. commit;
  635. /*---------------------------------------------------------------------------------------*/
  636. /* 3.1 Создаем таблицу job_list, в ней будет: ид из Joba и из связки */
  637. /*---------------------------------------------------------------------------------------*/
  638. SET TERM ^ ;
  639. CREATE OR ALTER PROCEDURE TMP_JOB_LIST_CREATE
  640. AS
  641. declare variable is_exist smallint;
  642. BEGIN
  643.  
  644. /* Гарантируем генератор */
  645. SELECT result FROM IS_GENERATOR_EXISTS('GEN_JOB_LIST_ID')
  646. INTO :is_exist;
  647.  
  648. IF (is_exist = 0) THEN
  649. BEGIN
  650. EXECUTE STATEMENT
  651. 'CREATE GENERATOR GEN_JOB_LIST_ID';
  652. END
  653.  
  654. /* Гарантируем таблицу */
  655. SELECT result FROM IS_TABLE_EXISTS('JOB_LIST')
  656. INTO :is_exist;
  657.  
  658. IF (is_exist = 0) THEN
  659. BEGIN
  660. EXECUTE STATEMENT
  661. 'CREATE TABLE JOB_LIST (
  662. ID_JOB_LIST INTEGER NOT NULL,
  663. NAME VARCHAR(200) NOT NULL,
  664. ID_OWNER INTEGER NOT NULL,
  665. constraint PK_JOB_LIST primary key (ID_JOB_LIST))';
  666. END
  667. END ^
  668. SET TERM ; ^
  669. commit;
  670. EXECUTE PROCEDURE TMP_JOB_LIST_CREATE;
  671. commit;
  672. DROP PROCEDURE TMP_JOB_LIST_CREATE;
  673. commit;
  674. /*---------------------------------------------------------------------------------------*/
  675. /* 3.2 Создаем триггер для генерации ID */
  676. /*---------------------------------------------------------------------------------------*/
  677. SET TERM ^;
  678. CREATE OR ALTER TRIGGER JOB_LIST_BI_GEN_ID
  679. FOR JOB_LIST
  680. ACTIVE BEFORE INSERT
  681. AS
  682. BEGIN
  683. IF (NEW.ID_JOB_LIST IS NULL) THEN
  684. NEW.ID_JOB_LIST = GEN_ID(GEN_JOB_LIST_ID, 1);
  685. END^
  686. SET TERM ; ^
  687. commit;
  688. /*---------------------------------------------------------------------------------------*/
  689. /* 3.3 раздаем гранты на таблицу */
  690. /*---------------------------------------------------------------------------------------*/
  691. EXECUTE PROCEDURE GIVE_GRANTS_TO_ALL('TABLE','JOB_LIST','ALL');
  692. commit;
  693. /*---------------------------------------------------------------------------------------*/
  694. /* 4.1 Создаем таблицу jobs_object, в ней будет: локальный id, тип объекта, его ид и ид задания */
  695. /*---------------------------------------------------------------------------------------*/
  696. SET TERM ^ ;
  697. CREATE OR ALTER PROCEDURE TMP_JOBS_OBJECT_CREATE
  698. AS
  699. declare variable is_exist smallint;
  700. BEGIN
  701.  
  702. /* Гарантируем генератор */
  703. SELECT result FROM IS_GENERATOR_EXISTS('GEN_JOBS_OBJECT_ID')
  704. INTO :is_exist;
  705.  
  706. IF (is_exist = 0) THEN
  707. BEGIN
  708. EXECUTE STATEMENT
  709. 'CREATE GENERATOR GEN_JOBS_OBJECT_ID';
  710. END
  711.  
  712. /* Гарантируем таблицу */
  713. SELECT result FROM IS_TABLE_EXISTS('JOBS_OBJECT')
  714. INTO :is_exist;
  715.  
  716. IF (is_exist = 0) THEN
  717. BEGIN
  718. EXECUTE STATEMENT
  719. 'CREATE TABLE JOBS_OBJECT (
  720. ID_JOBS_OBJECT INTEGER NOT NULL,
  721. ID_JOB INTEGER NOT NULL,
  722. ID_JOBS_OBJECT_TYPE INTEGER NOT NULL,
  723. ID_OBJECT INTEGER NOT NULL,
  724. constraint PK_JOBS_OBJECT primary key (ID_JOBS_OBJECT))';
  725. END
  726. END ^
  727. SET TERM ; ^
  728. commit;
  729. EXECUTE PROCEDURE TMP_JOBS_OBJECT_CREATE;
  730. commit;
  731. DROP PROCEDURE TMP_JOBS_OBJECT_CREATE;
  732. commit;
  733. /*---------------------------------------------------------------------------------------*/
  734. /* 4.2 Создаем триггер для генерации ID */
  735. /*---------------------------------------------------------------------------------------*/
  736. SET TERM ^;
  737. CREATE OR ALTER TRIGGER JOBS_OBJECT_BI_GEN_ID
  738. FOR JOBS_OBJECT
  739. ACTIVE BEFORE INSERT
  740. AS
  741. BEGIN
  742. IF (NEW.ID_JOBS_OBJECT IS NULL) THEN
  743. NEW.ID_JOBS_OBJECT = GEN_ID(GEN_JOBS_OBJECT_ID, 1);
  744. END^
  745. SET TERM ; ^
  746. commit;
  747. /*---------------------------------------------------------------------------------------*/
  748. /* 4.3 раздаем гранты на таблицу */
  749. /*---------------------------------------------------------------------------------------*/
  750. EXECUTE PROCEDURE GIVE_GRANTS_TO_ALL('TABLE','JOBS_OBJECT','ALL');
  751. commit;
  752. /*---------------------------------------------------------------------------------------*/
  753. /* В очередной раз становимся лучше. теперь так: для запускающих задание объектов одна таблица
  754. , различаем по типам - 1 - события, 2- задачи, дальше разберемся*/
  755. /*---------------------------------------------------------------------------------------*/
  756. SET TERM ^ ;
  757. CREATE OR ALTER PROCEDURE TMP_EVENT_JOBS_CREATE
  758. AS
  759. declare variable is_exist smallint;
  760. BEGIN
  761.  
  762. SELECT result FROM IS_TABLE_EXISTS('JOBBERS')
  763. INTO :is_exist;
  764.  
  765. IF (is_exist = 0) THEN
  766. BEGIN
  767. EXECUTE STATEMENT
  768. 'CREATE TABLE JOBBERS (
  769. ID_JOB_LIST INTEGER NOT NULL,
  770. ID_JOBBER INTEGER NOT NULL,
  771. ID_JOBBER_TYPE INTEGER NOT NULL,
  772. constraint PK_JOBBERS primary key (ID_JOB_LIST, ID_JOBBER, ID_JOBBER_TYPE))';
  773. END
  774. END ^
  775. SET TERM ; ^
  776. commit;
  777. EXECUTE PROCEDURE TMP_EVENT_JOBS_CREATE;
  778. commit;
  779. DROP PROCEDURE TMP_EVENT_JOBS_CREATE;
  780. commit;
  781. /*---------------------------------------------------------------------------------------*/
  782. /* раздаем гранты на таблицу */
  783. /*---------------------------------------------------------------------------------------*/
  784. EXECUTE PROCEDURE GIVE_GRANTS_TO_ALL('TABLE','JOBBERS','ALL');
  785. commit;
  786. /*---------------------------------------------------------------------------------------*/
  787. /* добавляем признак "Выполненное задание" в события */
  788. /*---------------------------------------------------------------------------------------*/
  789. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('CALENDAR_PERIODS', 'ISEXECT', 'SMALLINT');
  790.  
  791. RESULT
  792. =======
  793. 1
  794.  
  795. commit;
  796. /*---------------------------------------------------------------------------------------*/
  797. /* сбрасываем этот признак для событий, которые уже наступили*/
  798. /*---------------------------------------------------------------------------------------*/
  799. UPDATE CALENDAR_PERIODS SET ISEXECT = 1 WHERE START_DATE < 'NOW';
  800. commit;
  801. /*---------------------------------------------------------------------------------------*/
  802. /* stasy: Задания по событиям - конец*/
  803. /*---------------------------------------------------------------------------------------*/
  804. /*---------------------------------------------------------------------------------------*/
  805. /* stasy: Цепочки задач - начало*/
  806. /*---------------------------------------------------------------------------------------*/
  807. /*---------------------------------------------------------------------------------------*/
  808. /* добавляем поле для списков заданий в шаблоны задач */
  809. /*---------------------------------------------------------------------------------------*/
  810. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('TASK_TEMPLATES', 'ID_JOB_LIST', 'INTEGER');
  811.  
  812. RESULT
  813. =======
  814. 1
  815.  
  816. commit;
  817. /*---------------------------------------------------------------------------------------*/
  818. /* stasy: Цепочки задач - конец*/
  819. /*---------------------------------------------------------------------------------------*/
  820.  
  821. /* Делаем процедуру, которая строит дерево инициаторов или контролеров типа документа в зависимости от параметра i_right_kind */
  822. SET TERM ^ ;
  823.  
  824. CREATE OR ALTER PROCEDURE GETPERMREE_FOR_EMPLOYER_DOC (
  825. i_id integer,
  826. i_doctypeid integer,
  827. i_right_kind integer)
  828. returns (
  829. o_id integer,
  830. o_name varchar(200),
  831. o_level integer)
  832. as
  833. declare variable l_k smallint;
  834. declare variable l_empid integer;
  835. declare variable l_pred_level integer;
  836. begin
  837. l_k = 0;
  838. l_pred_level = 0;
  839. for select O_ID,O_NAME,O_LEVEL
  840. from GETPERMISSIONTREE_FOR_EMPLOYER (:i_id, 0)
  841. into :O_ID, :o_name, :o_level
  842. do
  843. begin
  844. l_k = 0;
  845. for select p.id_employer
  846. from permission p
  847. join employer e on e.id = p.id_employer
  848. where e.id_department=:o_id and p.id_boss=:i_id and p.enabled>0 and :l_k=0
  849. into :L_EMPID
  850. do
  851. begin
  852. if (exists(select grc.id_object
  853. from grouprights_content grc
  854. join GROUPRIGHTS_EMPLOYER gre on gre.id_groupright = grc.id_groupright
  855. where gre.id_employer = :L_EMPID and
  856. grc.right_kind=:i_right_kind and
  857. grc.id_object=:i_doctypeid)) then
  858. l_k=1;
  859. end
  860. if (l_k=1) then
  861. begin
  862. if (o_level - l_pred_level > 1) then
  863. o_level = o_level - 1;
  864. l_pred_level = o_level;
  865. suspend;
  866. end
  867. end
  868. end^
  869.  
  870. SET TERM ; ^
  871. commit;
  872.  
  873. EXECUTE PROCEDURE GIVE_GRANTS_TO_ALL('PROCEDURE','GETPERMREE_FOR_EMPLOYER_DOC','EXECUTE');
  874. commit;
  875.  
  876. /* Признак "Скрывать при поиске" для полей типа задачи */
  877. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('META_FIELD', 'ISHIDEINSEARCH', 'SMALLINT');
  878.  
  879. RESULT
  880. =======
  881. 1
  882.  
  883. commit;
  884.  
  885. /* Шаблон справочника */
  886. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('META_FIELD', 'DICTIONARY_TEMPLATE', 'VARCHAR(1000)');
  887.  
  888. RESULT
  889. =======
  890. 1
  891.  
  892. commit;
  893.  
  894. /* Флаг необходимости смены пароля */
  895. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('EMPLOYER', 'NEEDPASSWORDCHANGE', 'SMALLINT');
  896.  
  897. RESULT
  898. =======
  899. 1
  900.  
  901. commit;
  902.  
  903. /* Elena - Добавила сброс флага NEEDPASSWORDCHANGE при смене пароля*/
  904. SET TERM ^ ;
  905.  
  906. CREATE OR ALTER TRIGGER EMPLOYER_AU0 FOR EMPLOYER
  907. ACTIVE AFTER UPDATE POSITION 0
  908. as
  909. declare variable bossid integer;
  910. declare variable fbossid integer;
  911. declare variable projid integer;
  912. declare variable flag integer;
  913. declare variable l_empid integer;
  914. declare variable l_isdeleted integer;
  915. declare variable l_enabled smallint;
  916. begin
  917. if (new.isdeleted = 1 and old.isdeleted = 0) then
  918. begin
  919. /* for select id_boss
  920. from permission
  921. where id_employer = new.id and
  922. enabled >0
  923. into :l_empid
  924. do
  925. begin
  926. select isdeleted from employer where id = :l_empid
  927. into :l_isdeleted;
  928. if (l_isdeleted=0) then
  929. execute procedure set_permission_dep (l_empid, new.id);
  930. end */
  931.  
  932. update permission
  933. set enabled=0
  934. where id_boss=new.id;
  935.  
  936. /* update permission
  937. set enabled=0
  938. where id_employer=new.id; */
  939.  
  940. /* Удаляем из всех пользовательских деревьев */
  941. delete from ud_employer where id_employer=new.id;
  942. end
  943.  
  944. if (new.isdeleted = 0 and old.isdeleted=1) then
  945. execute procedure convertpermissions (new.id, new.isboss);
  946.  
  947. if (new.id_department != old.id_department) then
  948. begin
  949. for select distinct t.id_project
  950. from grouptask gt
  951. left join task t on (gt.id_task=t.id)
  952. where gt.id_employer = old.id and gt.is_respperson=1
  953. into :projid
  954. do
  955. begin
  956. flag = null;
  957. select count(id_project) from PROJECT_DEP
  958. where id_Project = :projid and ID_Department = new.id_department
  959. into :flag; /*проверяем не привязан ли уже этот проект к новому подразделению*/
  960.  
  961. if ((flag is null) or (flag = 0)) then /*если нет, то привязываем*/
  962. insert into PROJECT_DEP (ID_Project, ID_Department)
  963. values (:projid,new.id_department);
  964.  
  965. flag = null;
  966. /* old begin */
  967. /* select count (t.id) --проверяем остались ли еще задачи для этого проекта в старом подразделении
  968. from task t
  969. join employer e on t.id_employer = e.id
  970. where t.id_project =:projid and
  971. t.ID_employer != old.id and
  972. e.id_department = old.id_department
  973. into :flag;
  974. */ /* old end */
  975.  
  976. /* new begin */
  977. select count (t.id) /*проверяем остались ли еще задачи для этого проекта в старом подразделении*/
  978. from task t
  979. join grouptask gt on (t.id = gt.id_task and gt.is_worker = 1)
  980. join employer e on gt.id_employer = e.id
  981. where t.id_project =:projid and
  982. gt.ID_employer != old.id and
  983. e.id_department = old.id_department
  984. into :flag;
  985. /* new end */
  986.  
  987. if ((flag is null) or (flag = 0)) then /*если нет, то удаляем привязку этого проекта к подразделению*/
  988. delete from PROJECT_DEP where
  989. id_project = :projid and
  990. id_department = old.id_department;
  991. end
  992.  
  993. update permission
  994. set enabled = 0
  995. where id_boss = new.id and
  996. is_manual=0;
  997. execute procedure convertpermissions (new.id, new.isboss);
  998. /*Обновляем deppermission для боссов данного пользователя*/
  999. for select id_boss,enabled
  1000. from permission
  1001. where id_employer = new.id and
  1002. enabled <> 0
  1003. into :l_empid,:l_enabled
  1004. do
  1005. begin
  1006. select isdeleted from employer where id = :l_empid
  1007. into :l_isdeleted;
  1008. if (l_isdeleted = 0) then
  1009. begin
  1010. /* Проверяем имеет ли начальник права на отдел в который перевели чела
  1011. * и если нет, то удаляем права начальника на чела
  1012. */
  1013. if (not (exists(select d.enabled
  1014. from deppermission d
  1015. where d.id_employer=:l_empid and
  1016. d.id_department = new.id_department and
  1017. d.enabled = :l_enabled))) then
  1018. delete from permission p
  1019. where p.id_boss = :l_empid and
  1020. p.id_employer = new.id;
  1021. else
  1022. execute procedure set_permission_dep (l_empid, new.id);
  1023.  
  1024.  
  1025. /*Проверяем старое подразделение и удаляем его из deppermission, если там
  1026. больше нет пользователей, на которых босс имеет права*/
  1027. if (not exists(select p.id_boss
  1028. from permission p
  1029. join employer e on e.id = p.id_employer
  1030. where e.id_department = old.id_department and
  1031. p.id_boss = :l_empid and
  1032. enabled = :l_enabled)) then
  1033. begin
  1034. delete from deppermission
  1035. where id_department = old.id_department and
  1036. id_employer = :l_empid and
  1037. enabled = :l_enabled;
  1038. end
  1039. end
  1040. end
  1041.  
  1042. end
  1043.  
  1044. if (old.isboss <> new.isboss) then /*смена статуса сотрудника, переделываем полномочия*/
  1045. execute procedure convertpermissions (new.id, new.isboss);
  1046.  
  1047. if (old.pass <> new.pass and old.needpasswordchange = new.needpasswordchange) then
  1048. update employer
  1049. set needpasswordchange = 0
  1050. where id = new.id;
  1051.  
  1052. if (old.name<>new.name or
  1053. old.isboss<>new.isboss or
  1054. old.login<>new.login or
  1055. old.pass<>new.pass or
  1056. old.isdeleted<>new.isdeleted or
  1057. old.email<>new.email or
  1058. old.cphone<>new.cphone or
  1059. old.workphone<>new.workphone or
  1060. old.birthdate<>new.birthdate or
  1061. old.postaddress<>new.postaddress or
  1062. old.homephone<>new.homephone or
  1063. old.cphone2<>new.cphone2 or
  1064. old.commnt<>new.commnt or
  1065. old.manpost<>new.manpost or
  1066. old.fastlogin<>new.fastlogin or
  1067. old.awayto<>new.awayto
  1068. ) then
  1069. update employer
  1070. set name = new.name,
  1071. isboss = new.isboss,
  1072. login = new.login,
  1073. pass = new.pass,
  1074. isdeleted = new.isdeleted,
  1075. email = new.email,
  1076. cphone = new.cphone,
  1077. workphone = new.workphone,
  1078. birthdate = new.birthdate,
  1079. postaddress = new.postaddress,
  1080. homephone = new.homephone,
  1081. cphone2 = new.cphone2,
  1082. commnt = new.commnt,
  1083. manpost = new.manpost,
  1084. fastlogin = new.fastlogin,
  1085. awayto=new.awayto
  1086. where parentid = new.id and
  1087. isdeleted = 0;
  1088. end^
  1089.  
  1090. SET TERM ; ^
  1091. commit;
  1092.  
  1093. /*-------------------------------------------------------------------------------------------------------------------------------*/
  1094. /* пункт меню "Интеграция с LDAP" */
  1095. /*-------------------------------------------------------------------------------------------------------------------------------*/
  1096.  
  1097. EXECUTE PROCEDURE ADDMENUITEMBYTAG(869, 'L_MENU_LDAP', 'http://ldapsync_host:ldapsync_port', 'L_MENU_ADMINISTRATION', 21, 1, 6, NULL);
  1098. commit;
  1099.  
  1100. /* Elena - Добавила выходной параметр id_tasktype*/
  1101. SET TERM ^ ;
  1102.  
  1103. CREATE OR ALTER PROCEDURE GETTASKINFO4SF (
  1104. idemployer integer,
  1105. idtask integer)
  1106. returns (
  1107. taskid integer,
  1108. tasknumber varchar(200),
  1109. priority integer,
  1110. taskname varchar(2000),
  1111. startdate date,
  1112. enddate date,
  1113. author varchar(10000),
  1114. controller varchar(10000),
  1115. responsible varchar(10000),
  1116. worker varchar(10000),
  1117. projectname varchar(10000),
  1118. tasktype varchar(10000),
  1119. taskstate char(4),
  1120. marker integer,
  1121. id_tasktype integer)
  1122. as
  1123. declare variable is_author smallint;
  1124. declare variable is_controller smallint;
  1125. declare variable is_responsible smallint;
  1126. declare variable is_worker smallint;
  1127. declare variable emp_name varchar(2000);
  1128. declare variable act_cnt integer;
  1129. declare variable istasknew smallint;
  1130. declare variable isactnew smallint;
  1131. declare variable isreport smallint;
  1132. declare variable isreject smallint;
  1133. declare variable i integer;
  1134. declare variable sql varchar(1000);
  1135. BEGIN
  1136. SQL = '';
  1137. if (idtask<>-1) then
  1138. begin
  1139. SQL = ' and t.ID = ' || :idtask;
  1140. end
  1141. for EXECUTE STATEMENT 'select
  1142. t.ID,
  1143. lower(t.NUMERATOR),
  1144. t.PRIORITY,
  1145. lower(t.NAME),
  1146. t.STARTDATE,
  1147. t.ENDDATE,
  1148. lower(p.NAME),
  1149. lower(md.NAME),
  1150. md.id,
  1151. ta.MARKER_COLOR,
  1152. t.action_count,
  1153. (1 - gt.IS_VIEWED_TASK),
  1154. (1-(case ta.IS_VIEW_NEW_ACTIONS when (ta.IS_VIEW_NEW_ACTIONS) then ta.IS_VIEW_NEW_ACTIONS else 0 end)),
  1155. t.ISREPORTED,
  1156. t.ISREJECTED
  1157. from
  1158. TASK t
  1159. join GROUPTASK gt on
  1160. t.ID = gt.ID_TASK
  1161. join PROJECT p on
  1162. p.id = t.ID_PROJECT
  1163. join META_DICTIONARY md on
  1164. md.ID = t.ID_META_DICTIONARY
  1165. left join TASK_ATTRIBUTES ta on
  1166. ta.ID_TASK = gt.ID_TASK and ta.id_employer=gt.id_original
  1167. where
  1168. gt.id_original = ' || :idemployer || ' and gt.task_state=0' || :SQL
  1169. into
  1170. :TASKID,
  1171. :TASKNUMBER,
  1172. :PRIORITY,
  1173. :TASKNAME,
  1174. :STARTDATE,
  1175. :ENDDATE,
  1176. :PROJECTNAME,
  1177. :TASKTYPE,
  1178. :ID_TASKTYPE,
  1179. :MARKER,
  1180. :ACT_CNT,
  1181. :istasknew,
  1182. :isactnew,
  1183. :isreport,
  1184. :isreject
  1185. do
  1186. begin
  1187. Author = '';
  1188. Controller = '';
  1189. Responsible = '';
  1190. Worker = '';
  1191. for
  1192. select
  1193. gt.IS_AUTHOR,
  1194. gt.IS_CONTROLER,
  1195. gt.IS_RESPPERSON,
  1196. gt.IS_WORKER,
  1197. e.NAME
  1198. from
  1199. GROUPTASK gt
  1200. join EMPLOYER e on
  1201. e.ID = gt.ID_EMPLOYER
  1202. where
  1203. gt.ID_TASK = :TASKID
  1204. into
  1205. :is_author,
  1206. :is_controller,
  1207. :is_responsible,
  1208. :is_worker,
  1209. :emp_name
  1210. do
  1211. begin
  1212. if (is_author = 1) then
  1213. begin
  1214. if (Author <> '') then Author = Author || ',';
  1215. Author = Author || emp_name;
  1216. end
  1217.  
  1218. if (is_controller = 1) then
  1219. begin
  1220. if (Controller <> '') then Controller = Controller || ',';
  1221. Controller = Controller || emp_name;
  1222. end
  1223.  
  1224. if (is_responsible = 1) then
  1225. begin
  1226. if (Responsible <> '') then Responsible = Responsible || ',';
  1227. Responsible = Responsible || emp_name;
  1228. end
  1229.  
  1230. if (is_worker = 1) then
  1231. begin
  1232. if (Worker <> '') then Worker = Worker || ',';
  1233. Worker = Worker || emp_name;
  1234. end
  1235. end
  1236.  
  1237. if ( ( (ACT_CNT=0)or(ACT_CNT is null) ) ) then isactnew = 0;
  1238. if (isreject is null) then isreject = 0;
  1239. taskstate = istasknew || isactnew || isreport || isreject;
  1240.  
  1241. SUSPEND;
  1242. end
  1243. END^
  1244.  
  1245. SET TERM ; ^
  1246. commit;
  1247.  
  1248. /*-------------------------------------------------------------------------------------------------------------------------------*/
  1249. /*stasy: shablon otobrajenia imeni documenta begining*/
  1250. /*-------------------------------------------------------------------------------------------------------------------------------*/
  1251. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('DOCTYPES', 'DISPLAY_NAME', 'VARCHAR(1000)');
  1252.  
  1253. RESULT
  1254. =======
  1255. 1
  1256.  
  1257. commit;
  1258. /*-------------------------------------------------------------------------------------------------------------------------------*/
  1259. /*shablon otobrajenia imeni documenta end*/
  1260. /*-------------------------------------------------------------------------------------------------------------------------------*/
  1261. /*tip resolucii - begin*/
  1262. /*isnachalno nepravilno bilo, chishu*/
  1263. /*-------------------------------------------------------------------------------------------------------------------------------*/
  1264. delete from doccards where FIELDID = 'RESOLUTION_TYPE' and FIELDTYPE = 104;
  1265. commit;
  1266. /*-------------------------------------------------------------------------------------------------------------------------------*/
  1267. SET TERM ^ ;
  1268. CREATE OR ALTER PROCEDURE DROD_FIELD_IF_EXIST
  1269. (
  1270. table_name varchar(50),
  1271. field_name varchar(50)
  1272. )
  1273. RETURNS
  1274. (
  1275. result SMALLINT
  1276. )
  1277. AS
  1278. DECLARE VARIABLE is_exist SMALLINT;
  1279. BEGIN
  1280. result = 0;
  1281.  
  1282. SELECT result FROM IS_FIELD_EXISTS(:table_name, :field_name)
  1283. INTO :is_exist;
  1284.  
  1285. IF (is_exist > 0) THEN
  1286. BEGIN
  1287. table_name = UPPER(table_name);
  1288. field_name = UPPER(field_name);
  1289.  
  1290. EXECUTE STATEMENT
  1291. 'ALTER TABLE ' || table_name || ' DROP ' || field_name ;
  1292.  
  1293. result = 1;
  1294. END
  1295.  
  1296. SUSPEND;
  1297. END^
  1298. SET TERM ; ^
  1299. COMMIT;
  1300. /*-------------------------------------------------------------------------------------------------------------------------------*/
  1301. EXECUTE PROCEDURE DROD_FIELD_IF_EXIST('DOCCARDS', 'RESOLUTION_TYPE');
  1302.  
  1303. RESULT
  1304. =======
  1305. 0
  1306.  
  1307. commit;
  1308. /*-------------------------------------------------------------------------------------------------------------------------------*/
  1309. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('DOCTYPES', 'RESOLUTION_TYPE', 'INTEGER');
  1310.  
  1311. RESULT
  1312. =======
  1313. 1
  1314.  
  1315. commit;
  1316. /*tip resolucii - end*/
  1317. /*-------------------------------------------------------------------------------------------------------------------------------*/
  1318.  
  1319. EXECUTE PROCEDURE ADD_INDEX_IF_DOES_NOT_EXIST('IDX_META_FIELD1','META_FIELD','NAME, ISDELETED');
  1320.  
  1321. RESULT
  1322. =======
  1323. 1
  1324.  
  1325. commit;
  1326.  
  1327. EXECUTE PROCEDURE ADD_INDEX_IF_DOES_NOT_EXIST('DOCTYPES_IDX1', 'DOCTYPES', 'ISDELETED');
  1328.  
  1329. RESULT
  1330. =======
  1331. 0
  1332.  
  1333. commit;
  1334.  
  1335. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  1336. /*01.03.2011, Alisa.Kot, task 270434
  1337. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  1338. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  1339. SET TERM ^ ;
  1340. CREATE OR ALTER PROCEDURE GETTASKEXECDOCBUTOUTDATE_1 (
  1341. I_FROM_DATE Timestamp,
  1342. I_TO_DATE Timestamp,
  1343. I_ID_DEPARTMENT Integer )
  1344. RETURNS (
  1345. O_TASKID Integer,
  1346. O_PROJID Integer,
  1347. O_DOC_EXEC_ID Integer )
  1348. AS
  1349. begin
  1350. for select t.id, t.id_project
  1351. from task t
  1352. where t.state = 1 and
  1353. t.isdeleted = 0 and
  1354. t.tsreport > t.enddate and
  1355. t.id_department = :i_id_department and
  1356. t.enddate between :i_from_date and :i_to_date and
  1357. t.tsreport between :i_from_date and :i_to_date
  1358. into :o_taskid, :O_PROJID
  1359. do
  1360. suspend;
  1361.  
  1362. end^
  1363. SET TERM ; ^
  1364. commit;
  1365.  
  1366. SET TERM ^ ;
  1367. CREATE OR ALTER PROCEDURE GETTASKEXECDOCBUTOUTDATE (
  1368. I_ID_EMPLOYER Integer,
  1369. I_ID_DEPARTMENT Integer,
  1370. I_ONLY_THIS_DEP Smallint,
  1371. I_FROM_DATE Timestamp,
  1372. I_TO_DATE Timestamp )
  1373. RETURNS (
  1374. O_TASK_NAME Varchar(2000),
  1375. O_AUTHOR Varchar(2000),
  1376. O_ADATE Timestamp,
  1377. O_TASKID Integer,
  1378. O_AUTHORID Integer,
  1379. O_TASKENDDATE Timestamp,
  1380. O_STATE Smallint,
  1381. O_ACT_EMPID Integer,
  1382. O_TASKSTARTDATE Timestamp,
  1383. O_EMPLOYERID Integer,
  1384. O_EMPLOYERNAME Varchar(2000),
  1385. O_ISBOSS Smallint,
  1386. O_PROJID Integer,
  1387. O_PROJECT_NAME Varchar(200),
  1388. O_DIFFTIME Timestamp,
  1389. O_NUMERATOR Varchar(1000),
  1390. O_TSREPORT Timestamp )
  1391. AS
  1392. DECLARE VARIABLE L_DEPID INTEGER;
  1393. DECLARE VARIABLE L_LAST_ACTIONID INTEGER;
  1394. DECLARE VARIABLE L_LAST_ACTIONTIME TIMESTAMP;
  1395. DECLARE VARIABLE L_REPORTDATE TIMESTAMP;
  1396. DECLARE VARIABLE L_LEFTDATE TIMESTAMP;
  1397. DECLARE VARIABLE L_RIGHTDATE TIMESTAMP;
  1398. DECLARE VARIABLE L_RESULT SMALLINT;
  1399. DECLARE VARIABLE L_ROOT_DEP INTEGER;
  1400. DECLARE VARIABLE L_HASCHILDS INTEGER;
  1401. DECLARE VARIABLE L_TASK_DOC_EXEC_ID INTEGER;
  1402. DECLARE VARIABLE L_DOCID INTEGER;
  1403. DECLARE VARIABLE L_DOC_TYPE_ID INTEGER;
  1404. DECLARE VARIABLE L_DOC_STATE SMALLINT;
  1405. DECLARE VARIABLE L_IS_WHITH_REPORT SMALLINT;
  1406. DECLARE VARIABLE L_ISREPORTED SMALLINT;
  1407. begin
  1408.  
  1409. if (:i_id_department is not null) then
  1410. begin
  1411. l_root_dep = :i_id_department;
  1412. end
  1413. else
  1414. select id_department from employer where id=:i_id_employer
  1415. into :l_root_dep;
  1416. if (:i_only_this_dep = 0) then
  1417. begin
  1418. select haschilds from department where id = :l_root_dep
  1419. into :l_haschilds;
  1420. if (:l_haschilds = 0) then
  1421. i_only_this_dep = 1;
  1422. end
  1423. for select g.o_taskid, g.o_projid
  1424. from gettaskexecdocbutoutdate_1(:i_from_date, :i_to_date, :l_root_dep) g
  1425. into :o_taskid, :o_projid
  1426. do
  1427. begin
  1428. execute procedure checkrightsfortask(:i_id_employer, :o_taskid)
  1429. returning_values :l_result;
  1430. if(:l_result = 1) then
  1431. begin
  1432. select t.name, t.startdate, t.enddate, t.la_id, t.iswithreport, t.isreported, t.tsreport, t.numerator
  1433. from task t
  1434. where t.id = :o_taskid
  1435. into :o_task_name, :o_taskstartdate, :o_taskenddate, :l_last_actionid, :l_is_whith_report, :l_isreported, :l_reportdate, :O_NUMERATOR;
  1436.  
  1437. select first 1 a.adate
  1438. from actions a
  1439. where a.id=:l_last_actionid
  1440. into :l_last_actiontime;
  1441.  
  1442. select first 1 gt.id_employer
  1443. from grouptask gt
  1444. where gt.id_task=:o_taskid and gt.is_author=1
  1445. into :o_authorid;
  1446.  
  1447. select first 1 gt.id_employer
  1448. from grouptask gt
  1449. where gt.id_task=:o_taskid and gt.is_respperson=1
  1450. into :o_employerid;
  1451.  
  1452. select name from employer where id = :o_authorid
  1453. into :o_author;
  1454.  
  1455. select p.name from project p
  1456. where p.id = :o_projid
  1457. into :O_PROJECT_NAME;
  1458.  
  1459. select name from employer where id = :o_employerid
  1460. into :o_employername;
  1461. /* if (l_is_whith_report=1) then
  1462. begin
  1463. if (l_isreported=1) then
  1464. begin
  1465. l_leftdate=:l_reportdate;
  1466. l_rightdate=:o_taskenddate;
  1467. O_DIFFTIME = cast((cast(:l_leftdate as timestamp)-cast(:l_rightdate as timestamp))*100 as integer)/100;
  1468. end
  1469. else
  1470. begin
  1471. O_DIFFTIME = cast((cast(:l_last_actiontime as timestamp)-cast(:o_taskenddate as timestamp))*100 as integer)/100;
  1472. end
  1473. end
  1474. else
  1475. begin
  1476. O_DIFFTIME = cast((cast(:l_last_actiontime as timestamp)-cast(:o_taskenddate as timestamp))*100 as integer)/100;
  1477. end
  1478. */
  1479. --O_DIFFTIME = :l_reportdate - :o_taskenddate;
  1480. O_TSREPORT = :l_reportdate;
  1481. suspend;
  1482. end
  1483. end
  1484. if (:i_only_this_dep = 0) then
  1485. begin
  1486. for select id_department
  1487. from deppermission
  1488. where id_employer=:i_id_employer and enabled > 0
  1489. into :l_depid
  1490. do
  1491. begin
  1492. select o_result from is_sub_dep(:l_depid, :l_root_dep) into :l_result;
  1493. if (:l_result = 1) then
  1494. begin
  1495. for select g.o_taskid, g.o_projid
  1496. from gettaskexecdocbutoutdate_1(:i_from_date, :i_to_date, :l_depid) g
  1497. into :o_taskid, :o_projid
  1498. do
  1499. begin
  1500. execute procedure checkrightsfortask(:i_id_employer, :o_taskid)
  1501. returning_values :l_result;
  1502. if(:l_result = 1) then
  1503. begin
  1504. select t.name, t.startdate, t.enddate, t.la_id, t.iswithreport, t.isreported, t.tsreport, t.numerator
  1505. from task t
  1506. where t.id = :o_taskid
  1507. into :o_task_name, :o_taskstartdate, :o_taskenddate, :l_last_actionid, :l_is_whith_report, :l_isreported, :l_reportdate, :O_NUMERATOR;
  1508.  
  1509. select first 1 a.adate
  1510. from actions a
  1511. where a.id=:l_last_actionid
  1512. into :l_last_actiontime;
  1513.  
  1514. select first 1 gt.id_employer
  1515. from grouptask gt
  1516. where gt.id_task=:o_taskid and gt.is_author=1
  1517. into :o_authorid;
  1518.  
  1519. select first 1 gt.id_employer
  1520. from grouptask gt
  1521. where gt.id_task=:o_taskid and gt.is_respperson=1
  1522. into :o_employerid;
  1523.  
  1524. select name from employer where id = :o_authorid
  1525. into :o_author;
  1526.  
  1527. select p.name from project p
  1528. where p.id = :o_projid
  1529. into :O_PROJECT_NAME;
  1530.  
  1531. select name from employer where id = :o_employerid
  1532. into :o_employername;
  1533. --O_DIFFTIME = :l_reportdate - :o_taskenddate;
  1534. O_TSREPORT = :l_reportdate;
  1535. suspend;
  1536. end
  1537. end
  1538. end
  1539. end
  1540. end
  1541. end^
  1542. SET TERM ; ^
  1543. commit;
  1544.  
  1545. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  1546. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  1547. SET TERM ^ ;
  1548. CREATE OR ALTER PROCEDURE GETOUTDATED_1 (
  1549. I_ID_EMPLOYER Integer,
  1550. I_IS_BOSS Smallint,
  1551. I_ID_DEPARTMENT Smallint )
  1552. RETURNS (
  1553. O_TASKID Integer,
  1554. O_EMPLOYERID Integer,
  1555. O_DEPID Integer )
  1556. AS
  1557. DECLARE VARIABLE L_IS_BOSS SMALLINT;
  1558. DECLARE VARIABLE L_ISSECRET SMALLINT;
  1559. begin
  1560. for
  1561. select t.id,t.issecret
  1562. from task t
  1563. where
  1564. t.isdeleted =0 and
  1565. t.id_department = :i_id_department and
  1566. (select o_result from checkrightsfortask (:I_ID_EMPLOYER, t.id)) = 1 and
  1567. t.enddate < 'NOW' and
  1568. t.state = 0
  1569. into :O_TASKID,:l_issecret
  1570. do
  1571. begin
  1572. if (:l_issecret=0 or (:l_issecret=1 and
  1573. exists (select gt.id_task
  1574. from grouptask gt
  1575. where gt.id_task=:o_taskid and
  1576. gt.id_original=:i_id_employer) ) ) then
  1577. begin
  1578. for select gt.id_employer
  1579. from grouptask gt
  1580. where gt.id_task = :O_TASKID and
  1581. (gt.is_respperson=1 or gt.is_worker=1)
  1582. into :O_EMPLOYERID
  1583. do
  1584. begin
  1585. select id_department,isboss from employer
  1586. where id = :O_EMPLOYERID
  1587. into :O_DEPID,:l_is_boss;
  1588. if ((:I_IS_BOSS=1 and :l_is_boss=1) or :I_IS_BOSS=0) then
  1589. suspend;
  1590. end
  1591. end
  1592. end
  1593. end^
  1594. SET TERM ; ^
  1595. commit;
  1596.  
  1597. SET TERM ^ ;
  1598. CREATE OR ALTER PROCEDURE GETOUTDATED (
  1599. I_ID_EMPLOYER Integer,
  1600. I_DEPID Integer,
  1601. I_ONLY_BOSS Smallint,
  1602. I_ONLY_THIS_DEP Smallint )
  1603. RETURNS (
  1604. NAME Varchar(2000),
  1605. TASK_NAME Varchar(2000),
  1606. AUTHOR Varchar(2000),
  1607. CURR_ACTION Blob sub_type 1,
  1608. ADATE Timestamp,
  1609. TASKID Integer,
  1610. AUTHORID Integer,
  1611. TASKENDDATE Timestamp,
  1612. STATE Smallint,
  1613. ACT_EMPID Integer,
  1614. TASKSTARTDATE Timestamp,
  1615. EMPLOYERID Integer,
  1616. EMPLOYERNAME Varchar(2000),
  1617. ISBOSS Smallint,
  1618. O_PROJECT_ID Integer,
  1619. O_PROJECT_NAME Varchar(200),
  1620. O_DIFFTIME Integer,
  1621. O_NUMERATOR Varchar(1000) )
  1622. AS
  1623. declare variable L_TASKID integer;
  1624. declare variable L_STARTDATE timestamp;
  1625. declare variable L_DEPID integer;
  1626. declare variable L_AUTHORNAME varchar(2000);
  1627. declare variable L_RESULT smallint;
  1628. begin
  1629. for select
  1630. distinct g1.o_taskid
  1631. from getpermissiontree (:I_ID_EMPLOYER, :I_DEPID) gpt,
  1632. getoutdated_1(:I_ID_EMPLOYER,:i_only_boss,:i_depid) g1
  1633. where gpt.o_id = g1.o_depid
  1634. into :TASKID
  1635. do
  1636. begin
  1637. select NAME,
  1638. TASK_NAME,
  1639. AUTHOR,
  1640. CURR_ACTION,
  1641. ADATE,
  1642. AUTHORID,
  1643. TASKENDDATE,
  1644. STATE,
  1645. ACT_EMPID,
  1646. TASKSTARTDATE,
  1647. EMPLOYERID,
  1648. EMPLOYERNAME,
  1649. ISBOSS,
  1650. O_PROJECT_ID,
  1651. O_PROJECT_NAME,
  1652. O_DIFFTIME,
  1653. O_NUMERATOR
  1654. from getoutdated_3(:TASKID)
  1655. into :NAME,
  1656. :TASK_NAME,
  1657. :AUTHOR,
  1658. :CURR_ACTION,
  1659. :ADATE,
  1660. :AUTHORID,
  1661. :TASKENDDATE,
  1662. :STATE,
  1663. :ACT_EMPID,
  1664. :TASKSTARTDATE,
  1665. :EMPLOYERID,
  1666. :EMPLOYERNAME,
  1667. :ISBOSS,
  1668. :O_PROJECT_ID,
  1669. :O_PROJECT_NAME,
  1670. :O_DIFFTIME,
  1671. :O_NUMERATOR;
  1672. suspend;
  1673. end
  1674. if (:i_only_this_dep = 0) then
  1675. begin
  1676. for select id_department
  1677. from deppermission
  1678. where id_employer=:i_id_employer and enabled > 0
  1679. into :l_depid
  1680. do
  1681. begin
  1682. select o_result from is_sub_dep(:l_depid, :i_depid) into :l_result;
  1683. if (:l_result = 1) then
  1684. begin
  1685. for select
  1686. distinct g1.o_taskid
  1687. from getpermissiontree (:I_ID_EMPLOYER, :L_DEPID) gpt,
  1688. getoutdated_1(:I_ID_EMPLOYER,:i_only_boss,:l_depid) g1
  1689. where gpt.o_id = g1.o_depid
  1690. into :TASKID
  1691. do
  1692. begin
  1693. select NAME,
  1694. TASK_NAME,
  1695. AUTHOR,
  1696. CURR_ACTION,
  1697. ADATE,
  1698. AUTHORID,
  1699. TASKENDDATE,
  1700. STATE,
  1701. ACT_EMPID,
  1702. TASKSTARTDATE,
  1703. EMPLOYERID,
  1704. EMPLOYERNAME,
  1705. ISBOSS,
  1706. O_PROJECT_ID,
  1707. O_PROJECT_NAME,
  1708. O_DIFFTIME,
  1709. O_NUMERATOR
  1710. from getoutdated_3(:TASKID)
  1711. into :NAME,
  1712. :TASK_NAME,
  1713. :AUTHOR,
  1714. :CURR_ACTION,
  1715. :ADATE,
  1716. :AUTHORID,
  1717. :TASKENDDATE,
  1718. :STATE,
  1719. :ACT_EMPID,
  1720. :TASKSTARTDATE,
  1721. :EMPLOYERID,
  1722. :EMPLOYERNAME,
  1723. :ISBOSS,
  1724. :O_PROJECT_ID,
  1725. :O_PROJECT_NAME,
  1726. :O_DIFFTIME,
  1727. :O_NUMERATOR;
  1728. suspend;
  1729. end
  1730. end
  1731. end
  1732. end
  1733. end^
  1734. SET TERM ; ^
  1735. commit;
  1736. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  1737. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  1738. SET TERM ^ ;
  1739. CREATE OR ALTER PROCEDURE REPORT1 (
  1740. I_ID_EMPLOYER Integer,
  1741. I_DEPID Integer,
  1742. STARTDATE Timestamp,
  1743. ENDDATE Timestamp,
  1744. I_ONLY_THIS_DEP Smallint )
  1745. RETURNS (
  1746. NAME Varchar(2000),
  1747. TASK_NAME Varchar(2000),
  1748. CURR_ACTION Blob sub_type 1,
  1749. ADATE Timestamp,
  1750. TASKID Integer,
  1751. ISSTARTED Smallint,
  1752. PROJNAME Varchar(200),
  1753. DEPPATH Varchar(2000),
  1754. TASKENDDATE Timestamp,
  1755. STATE Smallint,
  1756. ISREJECTED Smallint,
  1757. PROJ_ID Integer,
  1758. ACT_EMPID Integer,
  1759. ACT_FIRST Integer,
  1760. TASKSTARTDATE Timestamp,
  1761. ISBOSS Smallint,
  1762. ISTRASHPROJECT Smallint )
  1763. AS
  1764. declare variable L_STARTDATE timestamp;
  1765. declare variable L_DEPID integer;
  1766. declare variable L_AUTHORNAME varchar(2000);
  1767. declare variable L_RESULT Smallint;
  1768. begin
  1769. if (I_DEPID <> 0) then
  1770. for select rf.name,
  1771. rf.TASK_NAME,
  1772. rf.taskstartdate,
  1773. rf.TASKID,
  1774. rf.isstarted,
  1775. rf.ProjName,
  1776. rf.deppath,
  1777. rf.taskenddate,
  1778. rf.STATE,
  1779. rf.isrejected,
  1780. rf.PROJ_ID,
  1781. rf.isboss,
  1782. rf.istrashproject,
  1783. rf.curr_action,
  1784. rf.adate,
  1785. rf.act_empid,
  1786. rf.act_first
  1787. from getpermissiontree (:I_ID_EMPLOYER, :I_DEPID) gpt,
  1788. report1_fast(:i_id_employer,:startdate,:enddate) rf
  1789. where rf.depid = gpt.o_id
  1790. into :name,
  1791. :TASK_NAME,
  1792. :taskstartdate,
  1793. :TASKID,
  1794. :isstarted,
  1795. :ProjName,
  1796. :deppath,
  1797. :taskenddate,
  1798. :STATE,
  1799. :isrejected,
  1800. :PROJ_ID,
  1801. :isboss,
  1802. :istrashproject,
  1803. :curr_action,
  1804. :adate,
  1805. :act_empid,
  1806. :act_first
  1807. do
  1808. suspend;
  1809. else
  1810. for select rf.name,
  1811. rf.TASK_NAME,
  1812. rf.taskstartdate,
  1813. rf.TASKID,
  1814. rf.isstarted,
  1815. rf.ProjName,
  1816. rf.deppath,
  1817. rf.taskenddate,
  1818. rf.STATE,
  1819. rf.isrejected,
  1820. rf.PROJ_ID,
  1821. rf.isboss,
  1822. rf.istrashproject,
  1823. rf.curr_action,
  1824. rf.adate,
  1825. rf.act_empid,
  1826. rf.act_first
  1827. from getpermissiontree_for_employer (:I_ID_EMPLOYER,0) gpt,
  1828. report1_fast(:i_id_employer,:startdate,:enddate) rf
  1829. where rf.depid = gpt.o_id
  1830. into :name,
  1831. :TASK_NAME,
  1832. :taskstartdate,
  1833. :TASKID,
  1834. :isstarted,
  1835. :ProjName,
  1836. :deppath,
  1837. :taskenddate,
  1838. :STATE,
  1839. :isrejected,
  1840. :PROJ_ID,
  1841. :isboss,
  1842. :istrashproject,
  1843. :curr_action,
  1844. :adate,
  1845. :act_empid,
  1846. :act_first
  1847. do
  1848. suspend;
  1849.  
  1850. if (:i_only_this_dep = 0) then
  1851. begin
  1852. for select id_department
  1853. from deppermission
  1854. where id_employer=:i_id_employer and enabled > 0
  1855. into :l_depid
  1856. do
  1857. begin
  1858. select o_result from is_sub_dep(:l_depid, :i_depid) into :l_result;
  1859. if (:l_result = 1) then
  1860. begin
  1861. for select t.name,
  1862. t.id,
  1863. t.startdate,
  1864. t.enddate,
  1865. t.state,
  1866. t.id_project,
  1867. t.isrejected,
  1868. t.isstarted,
  1869. a.name,
  1870. a.isfirst,
  1871. a.adate,
  1872. a.id_employer,
  1873. e.name,
  1874. e.isboss
  1875. from actions a
  1876. join task t on t.la_id = a.id
  1877. left join employer e on a.id_employer=e.id
  1878. where a.adate between :startdate and :enddate and
  1879. t.isdeleted = 0 and
  1880. e.id_department= :l_depid and
  1881. (select o_result from checkrightsfortask(:i_id_employer, t.id)) = 1
  1882. into :task_name,
  1883. :taskid,
  1884. :taskstartdate,
  1885. :taskenddate,
  1886. :state,
  1887. :proj_id,
  1888. :isrejected,
  1889. :isstarted,
  1890. :curr_action,
  1891. :act_first,
  1892. :adate,
  1893. :act_empid,
  1894. :name,
  1895. :isboss
  1896. do
  1897. suspend;
  1898. end
  1899. suspend;
  1900. end
  1901. end
  1902. end^
  1903. SET TERM ; ^
  1904. commit;
  1905. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  1906. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  1907.  
  1908. /*------------------------------------------------------------------------------------------------------------------------------*/
  1909. /* Добавление столбца EXECTIME в таблицу DOCUMENTTEMPLATE*/
  1910. /*------------------------------------------------------------------------------------------------------------------------------*/
  1911.  
  1912. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('DOCUMENTTEMPLATE', 'EXECTIME', 'TIMESTAMP');
  1913.  
  1914. RESULT
  1915. =======
  1916. 0
  1917.  
  1918. commit;
  1919.  
  1920. /*------------------------------------------------------------------------------------------------------------------------------*/
  1921. /* Процедура для втавки актуального уровня в поле IS_CURRENT в таблице ROUTETREES */
  1922. /*------------------------------------------------------------------------------------------------------------------------------*/
  1923.  
  1924. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST_D('ROUTETREES', 'IS_CURRENT', 'INTEGER', '0');
  1925.  
  1926. RESULT
  1927. =======
  1928. 1
  1929.  
  1930. commit;
  1931.  
  1932. SET TERM ^ ;
  1933. CREATE PROCEDURE INSERTROUTEACTUALLEVELS
  1934. AS
  1935. declare variable idtask integer;
  1936. declare variable iscurrent integer;
  1937. declare variable iddocument integer;
  1938. declare variable r_stage integer;
  1939. declare variable current_doc integer;
  1940. declare variable is_exist smallint;
  1941. BEGIN
  1942. select count(is_current) from ROUTETREES where is_current > 0
  1943. into :is_exist;
  1944. if(is_exist = 0) then
  1945. BEGIN
  1946. current_doc=0;
  1947. for select max(stage) as stage, id_document from ROUTETREES
  1948. group by id_document
  1949. into :r_stage, :iddocument
  1950. DO
  1951. BEGIN
  1952. if(current_doc<>:iddocument) then
  1953. BEGIN
  1954. update ROUTETREES set is_current=0 where id_document=:iddocument;
  1955. select first 1 id_task from routetrees rt, task t
  1956. where rt.ID_TASK=t.ID and t.STATE=0 and rt.ID_DOCUMENT=:iddocument and rt.STAGE=:r_stage
  1957. into :idtask;
  1958.  
  1959. update ROUTETREES set is_current=1 where id_task=:idtask and id_document=:iddocument and stage=:r_stage;
  1960. current_doc=iddocument;
  1961.  
  1962. END
  1963. END
  1964. END
  1965. END ^
  1966. SET TERM ; ^
  1967.  
  1968. EXECUTE PROCEDURE INSERTROUTEACTUALLEVELS;
  1969. commit;
  1970.  
  1971. DROP PROCEDURE INSERTROUTEACTUALLEVELS;
  1972. commit;
  1973. /*------------------------------------------------------------------------------------*/
  1974. /*stasy - avto dobavlenie postanovchika v zadachi v raznie roly
  1975. nachalo*/
  1976. /*------------------------------------------------------------------------------------*/
  1977. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('TASK_TEMPLATES', 'REALAUTHOR_AS_AUTHOR', 'SMALLINT');
  1978.  
  1979. RESULT
  1980. =======
  1981. 1
  1982.  
  1983. commit;
  1984. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('TASK_TEMPLATES', 'REALAUTHOR_AS_RESPPERSON', 'SMALLINT');
  1985.  
  1986. RESULT
  1987. =======
  1988. 1
  1989.  
  1990. commit;
  1991. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('TASK_TEMPLATES', 'REALAUTHOR_AS_CONTROLER', 'SMALLINT');
  1992.  
  1993. RESULT
  1994. =======
  1995. 1
  1996.  
  1997. commit;
  1998. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('TASK_TEMPLATES', 'REALAUTHOR_AS_WORKER', 'SMALLINT');
  1999.  
  2000. RESULT
  2001. =======
  2002. 1
  2003.  
  2004. commit;
  2005. /*------------------------------------------------------------------------------------*/
  2006. /*konec*/
  2007. /*------------------------------------------------------------------------------------*/
  2008. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  2009. /*stasy & Elena: drop hlam*/
  2010. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  2011. delete from menuitems m where m.dmess_tagname = 'L_OPTIONS_DOCPREFS3' and m.item_id = 889;
  2012. commit;
  2013. delete from employer_settings where settings_key='DOCUMENT_PREFS_DEFAULT_SETTINGS';
  2014. commit;
  2015. delete from notification_prefs np where np.task_attribute = 2;
  2016. commit;
  2017. /* Delete search menu items */
  2018. delete from menuitems m where m.item_id in (951, 952, 953, 954, 955, 956) or m.dmess_tagname = 'L_GLOBAL_SEARCH';
  2019. commit;
  2020. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  2021. /*stasy - opoveshenie o vipolnenii kt*/
  2022. /*------------------------------------------------------------------------------------*/
  2023. SET TERM ^ ;
  2024. CREATE OR ALTER PROCEDURE TMP_KT_READY_NOTIFI
  2025. AS
  2026. declare variable is_exist smallint;
  2027. BEGIN
  2028. select count (np.task_attribute) from notification_prefs np where id_employer=0 and action_type = 20
  2029. INTO :is_exist;
  2030.  
  2031. IF (is_exist > 0) THEN exit;
  2032.  
  2033. INSERT INTO NOTIFICATION_PREFS
  2034. (ACTION_TYPE, TASK_ATTRIBUTE, ID_EMPLOYER, SMS, MAIL, SMS_DISABLE, MAIL_DISABLE, EDITION)
  2035. VALUES (20, 1, 0, 1, 1, 0, 0, NULL);
  2036.  
  2037. INSERT INTO NOTIFICATION_PREFS
  2038. (ACTION_TYPE, TASK_ATTRIBUTE, ID_EMPLOYER, SMS, MAIL, SMS_DISABLE, MAIL_DISABLE, EDITION)
  2039. VALUES (20, 3, 0, 1, 1, 0, 0, NULL);
  2040.  
  2041. INSERT INTO NOTIFICATION_PREFS
  2042. (ACTION_TYPE, TASK_ATTRIBUTE, ID_EMPLOYER, SMS, MAIL, SMS_DISABLE, MAIL_DISABLE, EDITION)
  2043. VALUES (20, 4, 0, 1, 1, 0, 0, NULL);
  2044.  
  2045. INSERT INTO NOTIFICATION_PREFS
  2046. (ACTION_TYPE, TASK_ATTRIBUTE, ID_EMPLOYER, SMS, MAIL, SMS_DISABLE, MAIL_DISABLE, EDITION)
  2047. VALUES (20, 5, 0, 1, 1, 0, 0, NULL);
  2048.  
  2049. INSERT INTO NOTIFICATION_PREFS
  2050. (ACTION_TYPE, TASK_ATTRIBUTE, ID_EMPLOYER, SMS, MAIL, SMS_DISABLE, MAIL_DISABLE, EDITION)
  2051. VALUES (20, 6, 0, 1, 1, 0, 0, NULL);
  2052.  
  2053. INSERT INTO NOTIFICATION_PREFS
  2054. (ACTION_TYPE, TASK_ATTRIBUTE, ID_EMPLOYER, SMS, MAIL, SMS_DISABLE, MAIL_DISABLE, EDITION)
  2055. VALUES (20, 7, 0, 1, 1, 0, 0, NULL);
  2056.  
  2057. INSERT INTO NOTIFICATION_PREFS
  2058. (ACTION_TYPE, TASK_ATTRIBUTE, ID_EMPLOYER, SMS, MAIL, SMS_DISABLE, MAIL_DISABLE, EDITION)
  2059. VALUES (20, 8, 0, 1, 1, 0, 0, NULL);
  2060.  
  2061.  
  2062. END ^
  2063. SET TERM ; ^
  2064. commit;
  2065. EXECUTE PROCEDURE TMP_KT_READY_NOTIFI;
  2066. commit;
  2067. DROP PROCEDURE TMP_KT_READY_NOTIFI;
  2068. commit;
  2069. /*------------------------------------------------------------------------------------*/
  2070. /*stasy - opoveshenie o vipolnenii kt - conec*/
  2071. /*------------------------------------------------------------------------------------*/
  2072. /*stasy - procedura proveraet, javlaetsy li odna zapis' spravochnika potomkom drugoy*/
  2073. /*------------------------------------------------------------------------------------*/
  2074. SET TERM ^ ;
  2075. CREATE OR ALTER PROCEDURE IS_PARENT_CHILDE_RECORD (
  2076. i_childe integer,
  2077. i_parent integer)
  2078. returns (
  2079. o_result integer)
  2080. as
  2081. declare variable temp_childe integer;
  2082. declare variable temp_perent integer;
  2083. begin
  2084. for select id_parent from meta_record where id = :i_childe
  2085. into :temp_perent
  2086. do
  2087. begin
  2088. if (:temp_perent = :i_parent) then
  2089. begin
  2090. o_result = 1;
  2091. suspend;
  2092. exit;
  2093. end
  2094. if (:temp_perent is null) then
  2095. begin
  2096. o_result = 0;
  2097. suspend;
  2098. exit;
  2099. end
  2100. select o_result from IS_PARENT_CHILDE_RECORD (:temp_perent, :i_parent)
  2101. into :o_result;
  2102. suspend;
  2103. end
  2104. end ^
  2105. SET TERM ; ^
  2106. commit;
  2107. /*------------------------------------------------------------------------------------*/
  2108. /*conec*/
  2109. /*------------------------------------------------------------------------------------*/
  2110. /*------------------------------------------------------------------------------------*/
  2111. /*stasy - indecsi dl'auskorenija otchetow*/
  2112. /*------------------------------------------------------------------------------------*/
  2113. EXECUTE PROCEDURE ADD_INDEX_IF_DOES_NOT_EXIST('DDOCUMENT_REPORTS_INDEX_1', 'DOCUMENTS', 'ISDELETED,STATE,REGDATE');
  2114.  
  2115. RESULT
  2116. =======
  2117. 0
  2118.  
  2119. commit;
  2120. EXECUTE PROCEDURE ADD_INDEX_IF_DOES_NOT_EXIST('DOC_TASK_REPORTS_INDEX_1', 'GROUPTASK', 'TASK_ID_DOCUMENT, ID_EMPLOYER');
  2121.  
  2122. RESULT
  2123. =======
  2124. 0
  2125.  
  2126. commit;
  2127. /*------------------------------------------------------------------------------------*/
  2128. /*------------------------------------------------------------------------------------*/
  2129. /*stasy - merzkiy trigger*/
  2130. /*------------------------------------------------------------------------------------*/
  2131. SET TERM ^ ;
  2132. CREATE OR ALTER PROCEDURE TMP_DROP_MERSKIY_TRIGGER
  2133. AS
  2134. declare variable is_exist smallint;
  2135. BEGIN
  2136. SELECT result FROM IS_TRIGGER_EXISTS('NOTICEVIEW_AU0')
  2137. INTO :is_exist;
  2138.  
  2139. IF (is_exist = 1) THEN
  2140. begin
  2141. EXECUTE STATEMENT
  2142. 'DROP TRIGGER NOTICEVIEW_AU0;';
  2143. end
  2144. END ^
  2145. SET TERM ; ^
  2146. commit;
  2147. EXECUTE PROCEDURE TMP_DROP_MERSKIY_TRIGGER;
  2148. commit;
  2149. DROP PROCEDURE TMP_DROP_MERSKIY_TRIGGER;
  2150. commit;
  2151. /*------------------------------------------------------------------------------------*/
  2152.  
  2153. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('NOTICEVIEW', 'ISDELETED', 'SMALLINT');
  2154.  
  2155. RESULT
  2156. =======
  2157. 1
  2158.  
  2159. commit;
  2160.  
  2161. /*---------------------------------------------------------------------------------*/
  2162. /*stasy - rasshirenniy obshii reestr*/
  2163. /*---------------------------------------------------------------------------------*/
  2164. SET TERM ^ ;
  2165. CREATE OR ALTER PROCEDURE GETTREE_ID_ONLI (
  2166. i_id integer)
  2167. returns (
  2168. o_id integer)
  2169. as
  2170. begin
  2171. O_ID = I_ID;
  2172. suspend;
  2173. for SELECT ID
  2174. FROM department d
  2175. WHERE PARENTID = :I_ID and isdeleted = 0
  2176. INTO :O_ID
  2177. do
  2178. begin
  2179. for SELECT o_id
  2180. FROM GETTREE_ID_ONLI (:O_ID)
  2181. INTO :O_ID
  2182. do
  2183. suspend;
  2184. end
  2185. end^
  2186.  
  2187. SET TERM ; ^
  2188. commit;
  2189.  
  2190. SET TERM ^ ;
  2191. CREATE OR ALTER PROCEDURE GET_FURIGHT_EMP_BY_DEP (
  2192. i_empid integer,
  2193. i_depid integer,
  2194. i_only_this_dep smallint)
  2195. returns (
  2196. o_id_department integer,
  2197. o_empid integer)
  2198. as
  2199. declare variable l_flag smallint;
  2200. declare variable l_depid integer;
  2201. begin
  2202.  
  2203. if (I_ONLY_THIS_DEP = 1) then
  2204. begin
  2205. for select id, e.id_department from employer e
  2206. join permission p on (p.id_boss = :i_empid and p.enabled = 1 and e.id = p.id_employer)
  2207. where e.id_department = :I_DEPID and
  2208. e.isdeleted = 0
  2209. into :O_EMPID,
  2210. :o_id_department
  2211. do
  2212. suspend;
  2213. end
  2214. else
  2215. for select gt.o_id from GETTREE_ID_ONLI (:I_DEPID) gt
  2216. join deppermission dp on ( dp.id_department = gt.o_id
  2217. and id_employer = :i_empid
  2218. and enabled = 1 )
  2219.  
  2220. INTO :L_DEPID
  2221. do
  2222. begin
  2223. begin
  2224.  
  2225. for select id, e.id_department from employer e
  2226. join permission p on (p.id_boss = :i_empid and p.enabled = 1 and e.id = p.id_employer)
  2227. where e.id_department = :L_DEPID and
  2228. e.isdeleted = 0
  2229. into :O_EMPID,
  2230. :o_id_department
  2231. do
  2232. suspend;
  2233.  
  2234. end
  2235.  
  2236. end
  2237. END^
  2238.  
  2239. SET TERM ; ^
  2240. commit;
  2241. /*--------------------------------------------------------------------------------------------------------*/
  2242. SET TERM ^ ;
  2243. CREATE OR ALTER PROCEDURE GETDOCUMENTS_REGISTRY (
  2244. i_id_employer integer,
  2245. i_id_department integer,
  2246. i_id_doctype integer,
  2247. i_only_thisdep smallint,
  2248. i_from_date timestamp,
  2249. i_to_date timestamp)
  2250. returns (
  2251. o_id_document integer,
  2252. o_createdate timestamp,
  2253. o_regdate timestamp,
  2254. o_state smallint,
  2255. o_taskid integer,
  2256. o_doc_version integer,
  2257. o_document_files varchar(30000))
  2258. as
  2259. declare variable l_rootdepid integer;
  2260. declare variable l_department integer;
  2261. begin
  2262. if (i_id_department is null) then
  2263. select id_department from employer where id = :i_id_employer
  2264. into :l_rootdepid;
  2265. else
  2266. l_rootdepid = :i_id_department;
  2267.  
  2268. begin
  2269.  
  2270. for select distinct d.id , (select first 1 g.id_task
  2271. from grouptask g
  2272. where g.task_id_document = d.id
  2273. and g.task_id_document <>0
  2274. and g.task_state = 0), d.id_department
  2275.  
  2276. from documents d
  2277. where d.id_department in (select o_id from GETTREE_ID_ONLI (:l_rootdepid))
  2278. and d.regdate >= :i_from_date
  2279. and d.regdate <= :i_to_date
  2280. and d.id_doctype = :I_ID_DOCTYPE
  2281. and
  2282. (
  2283. (d.id_author in (select p.id_employer
  2284. from permission p
  2285. where p.id_boss = :i_id_employer
  2286. and p.enabled = 1))
  2287. or
  2288. (d.id in (select distinct g.task_id_document
  2289. from grouptask g
  2290. where g.id_employer in
  2291. (select p.id_employer
  2292. from permission p
  2293. where p.id_boss = :i_id_employer
  2294. and p.enabled = 1)
  2295. and g.task_id_document <>0)
  2296. )
  2297. )
  2298.  
  2299.  
  2300.  
  2301.  
  2302. into :o_id_document,
  2303. :o_taskid,
  2304. :l_department
  2305.  
  2306. do
  2307. begin
  2308. if (i_only_thisdep = 0 or l_department = i_id_department)
  2309. then
  2310. begin
  2311. select
  2312. d.createdate,
  2313. d.regdate,
  2314. d.state,
  2315. d.doc_version
  2316.  
  2317. from documents d
  2318. where d.id=:o_id_document
  2319.  
  2320. into
  2321.  
  2322. :o_createdate,
  2323. :o_regdate,
  2324. :o_state,
  2325. :o_doc_version;
  2326.  
  2327. select o_document_files from get_doc_files_list(:o_id_document,0)
  2328. into :o_document_files;
  2329. suspend;
  2330.  
  2331. end
  2332. end
  2333. end
  2334.  
  2335. END^
  2336.  
  2337. SET TERM ; ^
  2338. commit;
  2339.  
  2340. /*-------------------------------------------------------------------------------------------------------------*/
  2341. /*ryazanova -----------dobavlenie v adresnyju knigy polzovatelej(292714)----------------------------------------*/
  2342. SET TERM ^ ;
  2343. CREATE OR ALTER PROCEDURE UPDATE_ADRESS_BOOK
  2344. AS
  2345. DECLARE VARIABLE lRecID INTEGER;
  2346. DECLARE VARIABLE lDepID INTEGER;
  2347. DECLARE VARIABLE lEmp_ID_Rec INTEGER;
  2348. BEGIN
  2349. FOR
  2350. select d.id_record, em.id_department, em.id_rec_dict
  2351. from employer em, dictionaryrecordtype d
  2352. where em.id_rec_dict = d.id_record and em.isdeleted = 0 and d.id_system = 0
  2353. and em.parentid is null and em.id_department is not null
  2354. INTO :lRecID, :lDepID, :lEmp_ID_Rec
  2355. DO
  2356. BEGIN
  2357. IF (:lRecID IS NOT NULL) THEN
  2358. BEGIN
  2359. UPDATE dictionaryrecordtype d
  2360. SET d.is_system = 1, d.id_system = :lDepID
  2361. WHERE d.id_record = :lRecID;
  2362. END
  2363. END
  2364. END
  2365. ^
  2366.  
  2367. SET TERM ; ^
  2368.  
  2369. EXECUTE PROCEDURE UPDATE_ADRESS_BOOK;
  2370. DROP PROCEDURE UPDATE_ADRESS_BOOK;
  2371. COMMIT;
  2372. /*-------------------------------------------------------------------------------------------------------------*/
  2373. /*------------------------------------------------------------------------------------*/
  2374. /*pmv: polya adresnoi knigi po ymolchaniy */
  2375. /*------------------------------------------------------------------------------------*/
  2376. SET TERM ^ ;
  2377.  
  2378. CREATE OR ALTER procedure SET_ADDRESS_BOOK
  2379. as
  2380. begin
  2381. IF (NOT EXISTS(SELECT
  2382. SETTINGS_VALUE
  2383. FROM EMPLOYER_SETTINGS where (ID_EMPLOYER is null) and (SETTINGS_KEY='table-contacts-grid-state'))) THEN
  2384. BEGIN
  2385. update EMPLOYER_SETTINGS set SETTINGS_VALUE='[{"dataIndex":"path","header":"","sortable":true,"type":1,"width":200,"id":0},{"dataIndex":"f38","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":1},{"dataIndex":"f39","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":2},{"dataIndex":"f40","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":3},{"dataIndex":"f41","header":"","sortable":true,"type":5,"width":90,"hidden":false,"id":4},{"dataIndex":"f42","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":5},{"dataIndex":"f43","header":"","sortable":true,"type":12,"width":20,"hidden":false,"id":6},{"dataIndex":"f44","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":7},{"dataIndex":"f45","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":8},{"dataIndex":"f46","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":9},{"dataIndex":"f47","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":10},{"dataIndex":"f48","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":11},{"dataIndex":"f49","header":"","sortable":true,"type":10,"width":200,"hidden":false,"id":12},{"dataIndex":"f50","header":"","sortable":true,"type":10,"width":200,"hidden":false,"id":13},{"dataIndex":"f51","header":"","sortable":true,"type":10,"width":200,"hidden":false,"id":14},{"dataIndex":"f52","header":"","sortable":true,"type":11,"width":200,"hidden":false,"id":15},{"dataIndex":"f53","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":16},{"dataIndex":"f54","header":"","sortable":true,"type":2,"width":200,"hidden":true,"id":17},{"dataIndex":"f122","header":"","sortable":true,"type":3,"width":100,"hidden":true,"id":18},{"dataIndex":"f123","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":19},{"dataIndex":"f124","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":20},{"dataIndex":"f125","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":21},{"dataIndex":"f126","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":22},{"dataIndex":"f127","header":"","sortable":true,"type":13,"width":200,"hidden":true,"id":23},{"dataIndex":"f128","header":"","sortable":true,"type":5,"width":90,"hidden":true,"id":24},{"dataIndex":"f149","header":"","sortable":true,"type":12,"width":20,"hidden":true,"id":33},{"dataIndex":"f140","header":"","sortable":true,"type":8,"width":200,"hidden":true,"id":30},{"dataIndex":"f131","header":"","sortable":true,"type":11,"width":200,"hidden":true,"id":25},{"dataIndex":"f143","header":"","sortable":true,"type":10,"width":200,"hidden":true,"id":31},{"dataIndex":"f144","header":"","sortable":true,"type":2,"width":200,"hidden":true,"id":32},{"dataIndex":"f134","header":"","sortable":true,"type":4,"width":50,"hidden":true,"id":26},{"dataIndex":"f135","header":"","sortable":true,"type":3,"width":100,"hidden":true,"id":27},{"dataIndex":"f136","header":"","sortable":true,"type":6,"width":20,"hidden":true,"id":28},{"dataIndex":"f137","header":"","sortable":true,"type":9,"width":200,"hidden":true,"id":29},{"dataIndex":"f150","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":34},{"dataIndex":"f152","header":"","sortable":true,"type":12,"width":20,"hidden":true,"id":35}]' where (SETTINGS_KEY='table-contacts-grid-state') and (SETTINGS_VALUE='[{"dataIndex":"path","header":"","sortable":true,"type":1,"width":200,"id":0},{"dataIndex":"f38","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":1},{"dataIndex":"f39","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":2},{"dataIndex":"f40","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":3},{"dataIndex":"f41","header":"","sortable":true,"type":5,"width":90,"hidden":true,"id":4},{"dataIndex":"f42","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":5},{"dataIndex":"f43","header":"","sortable":true,"type":12,"width":20,"hidden":true,"id":6},{"dataIndex":"f44","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":7},{"dataIndex":"f45","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":8},{"dataIndex":"f46","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":9},{"dataIndex":"f47","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":10},{"dataIndex":"f48","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":11},{"dataIndex":"f49","header":"","sortable":true,"type":10,"width":200,"hidden":true,"id":12},{"dataIndex":"f50","header":"","sortable":true,"type":10,"width":200,"hidden":true,"id":13},{"dataIndex":"f51","header":"","sortable":true,"type":10,"width":200,"hidden":true,"id":14},{"dataIndex":"f52","header":"","sortable":true,"type":11,"width":200,"hidden":true,"id":15},{"dataIndex":"f53","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":16},{"dataIndex":"f54","header":"","sortable":true,"type":2,"width":200,"hidden":true,"id":17},{"dataIndex":"f122","header":"","sortable":true,"type":3,"width":100,"hidden":true,"id":18},{"dataIndex":"f123","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":19},{"dataIndex":"f124","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":20},{"dataIndex":"f125","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":21},{"dataIndex":"f126","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":22},{"dataIndex":"f127","header":"","sortable":true,"type":13,"width":200,"hidden":true,"id":23},{"dataIndex":"f128","header":"","sortable":true,"type":5,"width":90,"hidden":true,"id":24},{"dataIndex":"f149","header":"","sortable":true,"type":12,"width":20,"hidden":true,"id":33},{"dataIndex":"f140","header":"","sortable":true,"type":8,"width":200,"hidden":true,"id":30},{"dataIndex":"f131","header":"","sortable":true,"type":11,"width":200,"hidden":true,"id":25},{"dataIndex":"f143","header":"","sortable":true,"type":10,"width":200,"hidden":true,"id":31},{"dataIndex":"f144","header":"","sortable":true,"type":2,"width":200,"hidden":true,"id":32},{"dataIndex":"f134","header":"","sortable":true,"type":4,"width":50,"hidden":true,"id":26},{"dataIndex":"f135","header":"","sortable":true,"type":3,"width":100,"hidden":true,"id":27},{"dataIndex":"f136","header":"","sortable":true,"type":6,"width":20,"hidden":true,"id":28},{"dataIndex":"f137","header":"","sortable":true,"type":9,"width":200,"hidden":true,"id":29},{"dataIndex":"f150","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":34},{"dataIndex":"f152","header":"","sortable":true,"type":12,"width":20,"hidden":true,"id":35}]');
  2386. INSERT INTO EMPLOYER_SETTINGS(SETTINGS_KEY, SETTINGS_VALUE) values ('table-contacts-grid-state', '[{"dataIndex":"path","header":"","sortable":true,"type":1,"width":200,"id":0},{"dataIndex":"f38","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":1},{"dataIndex":"f39","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":2},{"dataIndex":"f40","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":3},{"dataIndex":"f41","header":"","sortable":true,"type":5,"width":90,"hidden":false,"id":4},{"dataIndex":"f42","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":5},{"dataIndex":"f43","header":"","sortable":true,"type":12,"width":20,"hidden":false,"id":6},{"dataIndex":"f44","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":7},{"dataIndex":"f45","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":8},{"dataIndex":"f46","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":9},{"dataIndex":"f47","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":10},{"dataIndex":"f48","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":11},{"dataIndex":"f49","header":"","sortable":true,"type":10,"width":200,"hidden":false,"id":12},{"dataIndex":"f50","header":"","sortable":true,"type":10,"width":200,"hidden":false,"id":13},{"dataIndex":"f51","header":"","sortable":true,"type":10,"width":200,"hidden":false,"id":14},{"dataIndex":"f52","header":"","sortable":true,"type":11,"width":200,"hidden":false,"id":15},{"dataIndex":"f53","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":16},{"dataIndex":"f54","header":"","sortable":true,"type":2,"width":200,"hidden":true,"id":17},{"dataIndex":"f122","header":"","sortable":true,"type":3,"width":100,"hidden":true,"id":18},{"dataIndex":"f123","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":19},{"dataIndex":"f124","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":20},{"dataIndex":"f125","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":21},{"dataIndex":"f126","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":22},{"dataIndex":"f127","header":"","sortable":true,"type":13,"width":200,"hidden":true,"id":23},{"dataIndex":"f128","header":"","sortable":true,"type":5,"width":90,"hidden":true,"id":24},{"dataIndex":"f149","header":"","sortable":true,"type":12,"width":20,"hidden":true,"id":33},{"dataIndex":"f140","header":"","sortable":true,"type":8,"width":200,"hidden":true,"id":30},{"dataIndex":"f131","header":"","sortable":true,"type":11,"width":200,"hidden":true,"id":25},{"dataIndex":"f143","header":"","sortable":true,"type":10,"width":200,"hidden":true,"id":31},{"dataIndex":"f144","header":"","sortable":true,"type":2,"width":200,"hidden":true,"id":32},{"dataIndex":"f134","header":"","sortable":true,"type":4,"width":50,"hidden":true,"id":26},{"dataIndex":"f135","header":"","sortable":true,"type":3,"width":100,"hidden":true,"id":27},{"dataIndex":"f136","header":"","sortable":true,"type":6,"width":20,"hidden":true,"id":28},{"dataIndex":"f137","header":"","sortable":true,"type":9,"width":200,"hidden":true,"id":29},{"dataIndex":"f150","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":34},{"dataIndex":"f152","header":"","sortable":true,"type":12,"width":20,"hidden":true,"id":35}]');
  2387. END
  2388. suspend;
  2389. end
  2390. ^
  2391.  
  2392. SET TERM ; ^
  2393. commit;
  2394. execute procedure set_address_book;
  2395. commit;
  2396. drop procedure set_address_book;
  2397. commit;
  2398. /*-------------------------------------------------------------------------------------------------------------*/
  2399.  
  2400. /*valer00n: Сортировка папок библиотеки по типам*/
  2401. SET TERM ^ ;
  2402. ALTER PROCEDURE GET_DL_USERTREE (
  2403. I_ID_PARENT Integer,
  2404. I_LEVEL Integer,
  2405. EMPID Integer )
  2406. RETURNS (
  2407. O_ID Integer,
  2408. O_NAME Varchar(200),
  2409. O_LEVEL Integer,
  2410. O_RIGHTS Integer,
  2411. O_OBJ_TYPE Integer )
  2412. AS
  2413. DECLARE VARIABLE L_SUB_RIGHT SMALLINT;
  2414. DECLARE VARIABLE L_NEXT_LEVEL SMALLINT;
  2415. begin
  2416. L_NEXT_LEVEL=:i_level;
  2417. for select df.ID, df.NAME,dp.rights,dp.issubrights, df.OBJ_TYPE
  2418. from DLFOLDER df
  2419. join dlpermissions dp on (dp.id_dlfolder=df.id and dp.id_employer=:EMPID)
  2420. where df.isdeleted =0 and df.parentid=:I_ID_PARENT order by df.OBJ_TYPE,df.name
  2421. into :o_id,:o_name,:O_RIGHTS,:l_sub_right,:o_obj_type
  2422. do
  2423. begin
  2424. L_NEXT_LEVEL=:i_level;
  2425. if (:O_RIGHTS>0) then
  2426. begin
  2427. L_NEXT_LEVEL=:i_level+1;
  2428. o_level=:i_level;
  2429. suspend;
  2430. end
  2431. if (:O_RIGHTS>0 or :l_sub_right>0) then
  2432. begin
  2433. for select gdlt.o_id,gdlt.o_name,gdlt.o_level,gdlt.o_rights, gdlt.o_obj_type
  2434. from get_dl_usertree(:o_id,:l_next_level,:empid) gdlt
  2435. into :o_id,:o_name,:o_level,:o_rights,:o_obj_type
  2436. do
  2437. suspend;
  2438. end
  2439. end
  2440. end^
  2441. SET TERM ; ^
  2442. commit;
  2443.  
  2444. SET TERM ^ ;
  2445. ALTER PROCEDURE GETDLPERMTREE_FOR_EMPLOYER (
  2446. I_ID Integer )
  2447. RETURNS (
  2448. O_ID Integer,
  2449. O_NAME Varchar(2000),
  2450. O_LEVEL Integer,
  2451. RIGHTS Integer,
  2452. O_OBJ_TYPE Integer )
  2453. AS
  2454. DECLARE VARIABLE L_ROOTDEP INTEGER;
  2455. DECLARE VARIABLE L_ROOTDEP_NAME INTEGER;
  2456. DECLARE VARIABLE START_LEVEL INTEGER;
  2457. DECLARE VARIABLE IS_ADMIN INTEGER;
  2458. DECLARE VARIABLE ADMIN_DEP INTEGER;
  2459. begin
  2460. select id
  2461. from dlfolder
  2462. where parentid = 0
  2463. and isdeleted<>1
  2464. into :L_ROOTDEP;
  2465.  
  2466. select O_RESULT from GET_RIGHT_EMPLOYER_AND_GROUP(:I_ID,7,0) into :is_admin;
  2467.  
  2468. /* if (is_admin=1) then
  2469. begin
  2470. SELECT id, name, 0, 0
  2471. from dlfolder
  2472. where parentid = 0
  2473. and isdeleted<>1
  2474. into :O_ID, :O_NAME, :O_LEVEL, :RIGHTS;
  2475. suspend;
  2476.  
  2477. for
  2478. SELECT o_id, o_name, o_level,O_RIGHTS FROM GETDLOLDTREE(:L_ROOTDEP, 1, :I_ID)
  2479. INTO :O_ID, :O_NAME, :O_LEVEL,:RIGHTS
  2480. do
  2481. suspend;
  2482.  
  2483. select d.id from employer e join dlfolder d on d.id_obj=e.id_department
  2484. where e.id=:i_id and d.isdeleted=0 and d.obj_type=1 into :admin_dep;
  2485.  
  2486.  
  2487. SELECT id, name, 1, 0
  2488. from dlfolder d
  2489. where d.id=:admin_dep
  2490. into :O_ID, :O_NAME, :O_LEVEL, :RIGHTS;
  2491. suspend;
  2492. RIGHTS=3;
  2493. for
  2494. SELECT o_id, o_name, o_level FROM GETDLSYSTREE(:admin_dep, 1)
  2495. INTO :O_ID, :O_NAME, :O_LEVEL
  2496. do
  2497. suspend;
  2498.  
  2499. end
  2500. else begin */
  2501. for
  2502. SELECT o_id, o_name, o_level,O_RIGHTS,O_OBJ_TYPE FROM GET_DL_USERTREE(0, 0, :I_ID)
  2503. INTO :O_ID, :O_NAME, :O_LEVEL,:RIGHTS,:O_OBJ_TYPE
  2504. do
  2505. suspend;
  2506. --end
  2507. end^
  2508. SET TERM ; ^
  2509. commit;
  2510. /*------------------------------------------------------------*/
  2511.  
  2512. /*-------------------------------------------------------------------------------------------------------------*/
  2513. /*kos: edited the trigger for tasks and - close and deleted project*/
  2514. /*--------------------------------------------------------------------------------------------------------------*/
  2515. SET TERM ^ ;
  2516.  
  2517. CREATE OR ALTER trigger task_au0 for task
  2518. active before update position 0
  2519. as
  2520. declare variable task_id int;
  2521. declare variable task_count int;
  2522. declare variable l_idroutetree integer;
  2523. declare variable l_idemployer integer;
  2524. declare variable l_idnotice integer;
  2525. declare variable l_id_docexec integer;
  2526. declare variable l_task_valuation_id integer;
  2527. begin
  2528. --закрывается без доклада
  2529. if (new.iswithreport = 0 and old.state = 0 and new.state = 1) then new.tsreport = 'now';
  2530. --задача с докладом
  2531. if (new.iswithreport = 1) then
  2532. begin
  2533. --доклад отправлен, но задача не закрыта
  2534. if (old.isreported=0 and new.isreported=1 and new.state = 0) then
  2535. new.respp_report = 'now';
  2536. --задача закрыта
  2537. if (old.state = 0 and new.state = 1) then
  2538. new.tsreport = 'now';
  2539. --возвращена на доработку
  2540. if (old.isreported=1 and new.isreported=0 and new.state = 0) then
  2541. new.respp_report = null;
  2542. end
  2543. if (new.isdeleted=1 and old.isdeleted =0) then
  2544. begin
  2545. update attachment set isdeleted = 1
  2546. where id_task=new.id;
  2547. end
  2548. if (new.isdeleted=1 and old.isdeleted =0) then
  2549. begin
  2550. update attachment set isdeleted = 1
  2551. where id_task=new.id;
  2552. end
  2553. /* меняем task_state в grouptask */
  2554. update grouptask set task_state=new.state
  2555. where id_task=new.id and (task_state != new.state or task_state is null);
  2556. if (new.state =1 and old.state = 0) then /*закрытие задачи - снимаем с контроля*/
  2557. begin
  2558. delete from hiddentasks where id_task=new.id;
  2559. select count (id) from task
  2560. where id_project =old.id_project
  2561. and state= 0
  2562. into :task_count;
  2563. /*напоминания*/
  2564. for select n.id from notice n where n.id_task = new.id
  2565. into :l_idnotice do
  2566. begin
  2567. execute procedure delete_notice(:l_idnotice);
  2568. end
  2569.  
  2570. end
  2571. if (new.state = 0 and old.state = 1) then /*восстановление задачи + проект*/
  2572. begin
  2573. update project set state=0
  2574. where id=new.id_project and state!=0;
  2575. new.id_valuation=null;/*сбрасываем точку восстановленной*/
  2576. update grouptask gt set gt.is_viewed_task=0 where gt.id_task=new.id;
  2577. update actions a set a.examinated=0 where a.examinated=1 and a.id_task=new.id;
  2578. end
  2579. end
  2580. ^
  2581.  
  2582. SET TERM ; ^
  2583. COMMIT;
  2584.  
  2585. SET TERM ^ ;
  2586.  
  2587. CREATE OR ALTER trigger department_bu0 for department
  2588. active before update position 0
  2589. as
  2590. declare variable newname varchar (200);
  2591. declare variable l_count integer;
  2592. begin
  2593. if (new.isdeleted = 1 and old.isdeleted = 0) then
  2594. begin
  2595. update employer
  2596. set isdeleted =1
  2597. where id_department = new.id;
  2598. end
  2599. if (new.name <> old.name) then
  2600. begin
  2601. newname = new.name || ': {L_GLOBAL_TASK_OUTOFPROJ}';
  2602. update project set name = :newname
  2603. where ID_Department = new.id and istrash = 1;
  2604. end
  2605. end
  2606. ^
  2607.  
  2608. SET TERM ; ^
  2609. COMMIT;
  2610. /*-------------------------------------------------------------------------------------------------------------*/
  2611.  
  2612. EXECUTE PROCEDURE ADD_INDEX_IF_DOES_NOT_EXIST('NOTICE_IDX5', 'NOTICE', 'ISDELETED');
  2613.  
  2614. RESULT
  2615. =======
  2616. 1
  2617.  
  2618. commit;
  2619.  
  2620. EXECUTE PROCEDURE ADD_INDEX_IF_DOES_NOT_EXIST('GROUPTASK_IDX2', 'GROUPTASK', 'ID_ORIGINAL, IS_HIDDEN_TASK, SHOW_TASK_DATE');
  2621.  
  2622. RESULT
  2623. =======
  2624. 1
  2625.  
  2626. commit;
  2627.  
  2628. /*-------------------------------------------------------------------------------------------------------------*/
  2629. /* Alisa Kotova, svetograd.motiw.ru task 6675 - get arcive documents by type and registration date*/
  2630. SET TERM ^ ;
  2631. CREATE OR ALTER PROCEDURE GETDOCUMENTS_ARCHIVE_MY (
  2632. I_EMPLOYER_ID Integer,
  2633. I_REGDATE_FROM Timestamp,
  2634. I_REGDATE_TO Timestamp )
  2635. RETURNS (
  2636. O_DOC_TYPE Integer,
  2637. O_DOCID Integer,
  2638. O_IS_RIGHT_ARHIV Integer )
  2639. AS
  2640. declare variable is_emplouer integer; /*есть права на автора*/
  2641. declare variable is_autor integer; /*есть права на участника задач по документу*/
  2642. begin
  2643. /*----------------------------------------------------------------------------------------*/
  2644. for select d.id, (select p.ID_Boss
  2645. from permission p
  2646. where p.ID_Boss = :i_employer_id
  2647. and p.ID_Employer = d.id_author
  2648. and p.enabled = 1
  2649. ), d.id_doctype
  2650. from documents d
  2651. where d.regdate >= :i_regdate_from and d.regdate <= :i_regdate_to
  2652. and d.state = 4 and d.isdeleted = 0
  2653. into :o_docid,
  2654. :is_autor,
  2655. :o_doc_type
  2656. do
  2657. /*----------------------------------------------------------------------------------------*/
  2658. /*если есть права на атора документа, то все, в архив попадает*/
  2659. if (is_autor <> 0) then
  2660. begin
  2661. O_IS_RIGHT_ARHIV = 1;
  2662. suspend;
  2663. end
  2664. /*----------------------------------------------------------------------------------------*/
  2665. /*если нет, проверяем права на участников задач по документу (с ботами блин)*/
  2666. else
  2667. begin
  2668. select count (g.task_id_document)
  2669. from grouptask g
  2670. where g.task_id_document = :o_docid
  2671. and g.id_employer in (select p.id_employer from permission p
  2672. where p.id_boss = :i_employer_id
  2673. and p.enabled = 1)
  2674. into :is_emplouer;
  2675. /*----------------------------------------------------------------------------------------*/
  2676. /*если подходящие задачи есть, то все ок, попадает в отчет*/
  2677. if (is_emplouer <> 0) then
  2678. begin
  2679. O_IS_RIGHT_ARHIV = 1;
  2680. end
  2681. /*----------------------------------------------------------------------------------------*/
  2682. /*если нет, то без вариантов - этого документа в отчете нет*/
  2683. else
  2684. begin
  2685. O_IS_RIGHT_ARHIV = 0;
  2686. end
  2687. suspend;
  2688. end
  2689. end^
  2690. SET TERM ; ^
  2691. commit;
  2692.  
  2693. GRANT EXECUTE
  2694. ON PROCEDURE GETDOCUMENTS_ARCHIVE_MY TO SYSDBA;
  2695. commit;
  2696.  
  2697. /* PM Kratkaya informaciya*/
  2698. EXECUTE PROCEDURE ADDMENUITEMBYTAG(903, 'L_MENU_BRIEF_INFO', '/user/hellopageuser/', 'L_ADDITIONAL', 3, 1, 0, NULL);
  2699. commit;
  2700.  
  2701. /* Unique attribute for doccard field */
  2702. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST_D('DOCCARDS', 'ISUNIQUE', 'SMALLINT', '0');
  2703.  
  2704. RESULT
  2705. =======
  2706. 1
  2707.  
  2708. commit;
  2709.  
  2710. /*ryazanova---Ispravit' nazvanija zadach IRG (6780)*/
  2711. update task t
  2712. set t.name = (select t1.name from task t1 where t1.id = t.parentid) || ' (' || t.irg_name || ')'
  2713. where t.is_isolated = 1 and t.irg_name <> '';
  2714. commit;
  2715. /*-------------------------------------------------------------------------------------------------------------------------------*/
  2716. /*ryazanova: derevo podrazdelenij v obratnom porjadke*/
  2717. SET TERM ^ ;
  2718. CREATE OR ALTER PROCEDURE get_backward_tree (
  2719. dep_id integer)
  2720. returns (
  2721. o_id integer)
  2722. as
  2723. DECLARE VARIABLE L_K SMALLINT;
  2724. begin
  2725. O_ID = :dep_id;
  2726. suspend;
  2727. for SELECT PARENTID
  2728. FROM department d
  2729. WHERE ID = :dep_id and isdeleted = 0
  2730. INTO :O_ID
  2731. do
  2732. begin
  2733. for SELECT o_id
  2734. FROM get_backward_tree (:O_ID)
  2735. INTO :O_ID
  2736. do
  2737. suspend;
  2738. end
  2739. end
  2740. ^
  2741. SET TERM ; ^
  2742.  
  2743. commit;
  2744. /*-------------------------------------------------------------------------------------------------------------------------------*/
  2745. /* Ryazanova - На ботов полномочия не удалять*/
  2746. SET TERM ^ ;
  2747.  
  2748. CREATE OR ALTER TRIGGER EMPLOYER_AU0 FOR EMPLOYER
  2749. ACTIVE AFTER UPDATE POSITION 0
  2750. as
  2751. declare variable bossid integer;
  2752. declare variable fbossid integer;
  2753. declare variable projid integer;
  2754. declare variable flag integer;
  2755. declare variable l_empid integer;
  2756. declare variable l_isdeleted integer;
  2757. declare variable l_enabled smallint;
  2758. declare variable l_parentid integer;
  2759. begin
  2760. if (new.isdeleted = 1 and old.isdeleted = 0) then
  2761. begin
  2762. /* for select id_boss
  2763. from permission
  2764. where id_employer = new.id and
  2765. enabled >0
  2766. into :l_empid
  2767. do
  2768. begin
  2769. select isdeleted from employer where id = :l_empid
  2770. into :l_isdeleted;
  2771. if (l_isdeleted=0) then
  2772. execute procedure set_permission_dep (l_empid, new.id);
  2773. end */
  2774.  
  2775. update permission
  2776. set enabled=0
  2777. where id_boss=new.id;
  2778.  
  2779. /* update permission
  2780. set enabled=0
  2781. where id_employer=new.id; */
  2782.  
  2783. /* Удаляем из всех пользовательских деревьев */
  2784. delete from ud_employer where id_employer=new.id;
  2785. end
  2786.  
  2787. if (new.isdeleted = 0 and old.isdeleted=1) then
  2788. execute procedure convertpermissions (new.id, new.isboss);
  2789.  
  2790. if (new.id_department != old.id_department) then
  2791. begin
  2792. for select distinct t.id_project
  2793. from grouptask gt
  2794. left join task t on (gt.id_task=t.id)
  2795. where gt.id_employer = old.id and gt.is_respperson=1
  2796. into :projid
  2797. do
  2798. begin
  2799. flag = null;
  2800. select count(id_project) from PROJECT_DEP
  2801. where id_Project = :projid and ID_Department = new.id_department
  2802. into :flag; /*проверяем не привязан ли уже этот проект к новому подразделению*/
  2803.  
  2804. if ((flag is null) or (flag = 0)) then /*если нет, то привязываем*/
  2805. insert into PROJECT_DEP (ID_Project, ID_Department)
  2806. values (:projid,new.id_department);
  2807.  
  2808. flag = null;
  2809. /* old begin */
  2810. /* select count (t.id) --проверяем остались ли еще задачи для этого проекта в старом подразделении
  2811. from task t
  2812. join employer e on t.id_employer = e.id
  2813. where t.id_project =:projid and
  2814. t.ID_employer != old.id and
  2815. e.id_department = old.id_department
  2816. into :flag;
  2817. */ /* old end */
  2818.  
  2819. /* new begin */
  2820. select count (t.id) /*проверяем остались ли еще задачи для этого проекта в старом подразделении*/
  2821. from task t
  2822. join grouptask gt on (t.id = gt.id_task and gt.is_worker = 1)
  2823. join employer e on gt.id_employer = e.id
  2824. where t.id_project =:projid and
  2825. gt.ID_employer != old.id and
  2826. e.id_department = old.id_department
  2827. into :flag;
  2828. /* new end */
  2829.  
  2830. if ((flag is null) or (flag = 0)) then /*если нет, то удаляем привязку этого проекта к подразделению*/
  2831. delete from PROJECT_DEP where
  2832. id_project = :projid and
  2833. id_department = old.id_department;
  2834. end
  2835.  
  2836. update permission
  2837. set enabled = 0
  2838. where id_boss = new.id and
  2839. is_manual=0;
  2840. execute procedure convertpermissions (new.id, new.isboss);
  2841. select parentid from employer where id = new.id
  2842. into :l_parentid;
  2843. /*Обновляем deppermission для боссов данного пользователя*/
  2844. for select id_boss,enabled
  2845. from permission
  2846. where id_employer = new.id and
  2847. enabled <> 0
  2848. into :l_empid,:l_enabled
  2849. do
  2850. begin
  2851. select isdeleted from employer where id = :l_empid
  2852. into :l_isdeleted;
  2853. if (l_isdeleted = 0) then
  2854. begin
  2855. /* Проверяем имеет ли начальник права на отдел в который перевели чела
  2856. * и если нет, то удаляем права начальника на чела
  2857. */
  2858. if (not (exists(select d.enabled
  2859. from deppermission d
  2860. where d.id_employer=:l_empid and
  2861. d.id_department = new.id_department and
  2862. d.enabled = :l_enabled)) and :l_empid <> :l_parentid) then
  2863. delete from permission p
  2864. where p.id_boss = :l_empid and
  2865. p.id_employer = new.id;
  2866. else
  2867. execute procedure set_permission_dep (l_empid, new.id);
  2868.  
  2869.  
  2870. /*Проверяем старое подразделение и удаляем его из deppermission, если там
  2871. больше нет пользователей, на которых босс имеет права*/
  2872. if (not exists(select p.id_boss
  2873. from permission p
  2874. join employer e on e.id = p.id_employer
  2875. where e.id_department = old.id_department and
  2876. p.id_boss = :l_empid and
  2877. enabled = :l_enabled)) then
  2878. begin
  2879. delete from deppermission
  2880. where id_department = old.id_department and
  2881. id_employer = :l_empid and
  2882. enabled = :l_enabled;
  2883. end
  2884. end
  2885. end
  2886.  
  2887. end
  2888.  
  2889. if (old.isboss <> new.isboss) then /*смена статуса сотрудника, переделываем полномочия*/
  2890. execute procedure convertpermissions (new.id, new.isboss);
  2891.  
  2892. if (old.pass <> new.pass and old.needpasswordchange = new.needpasswordchange) then
  2893. update employer
  2894. set needpasswordchange = 0
  2895. where id = new.id;
  2896.  
  2897. if (old.name<>new.name or
  2898. old.isboss<>new.isboss or
  2899. old.login<>new.login or
  2900. old.pass<>new.pass or
  2901. old.isdeleted<>new.isdeleted or
  2902. old.email<>new.email or
  2903. old.cphone<>new.cphone or
  2904. old.workphone<>new.workphone or
  2905. old.birthdate<>new.birthdate or
  2906. old.postaddress<>new.postaddress or
  2907. old.homephone<>new.homephone or
  2908. old.cphone2<>new.cphone2 or
  2909. old.commnt<>new.commnt or
  2910. old.manpost<>new.manpost or
  2911. old.fastlogin<>new.fastlogin or
  2912. old.awayto<>new.awayto
  2913. ) then
  2914. update employer
  2915. set name = new.name,
  2916. isboss = new.isboss,
  2917. login = new.login,
  2918. pass = new.pass,
  2919. isdeleted = new.isdeleted,
  2920. email = new.email,
  2921. cphone = new.cphone,
  2922. workphone = new.workphone,
  2923. birthdate = new.birthdate,
  2924. postaddress = new.postaddress,
  2925. homephone = new.homephone,
  2926. cphone2 = new.cphone2,
  2927. commnt = new.commnt,
  2928. manpost = new.manpost,
  2929. fastlogin = new.fastlogin,
  2930. awayto=new.awayto
  2931. where parentid = new.id and
  2932. isdeleted = 0;
  2933. end^
  2934.  
  2935. SET TERM ; ^
  2936. commit;
  2937.  
  2938. /*-------------------------------------------------------------------------------------------------------------------------------*/
  2939.  
  2940. /* Priznak dostupa */
  2941. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('EMPLOYER', 'ACCESS_TOKEN', 'VARCHAR(32)');
  2942.  
  2943. RESULT
  2944. =======
  2945. 1
  2946.  
  2947. commit;
  2948.  
  2949. /* Srok deystviya priznaka dostupa */
  2950. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('EMPLOYER', 'EXPIRE_DATE', 'TIMESTAMP');
  2951.  
  2952. RESULT
  2953. =======
  2954. 1
  2955.  
  2956. commit;
  2957. /*--------------------------------------------------------------------------------------------------*/
  2958. /*stasy - prava na proekty nachalo*/
  2959. SET TERM ^ ;
  2960. CREATE OR ALTER PROCEDURE GETPROJECT (
  2961. i_id_employer integer,
  2962. i_show_doc_projects smallint)
  2963. returns (
  2964. o_id integer,
  2965. o_name varchar(200),
  2966. o_description varchar(2000),
  2967. o_startdate timestamp,
  2968. o_enddate timestamp,
  2969. o_depname varchar(2000))
  2970. as
  2971. begin
  2972. if (i_show_doc_projects = 1) then
  2973. begin
  2974. for select distinct d.name,
  2975. p.id,
  2976. p.name,
  2977. p.description,
  2978. p.startdate,
  2979. p.enddate
  2980. from project p
  2981. join department d on (p.id_department = d.id)
  2982. left join task t on (p.id = t.id_project)
  2983. where
  2984. p.isdeleted =0
  2985. and p.state = 0
  2986. --and p.id_document is null
  2987. and
  2988. (
  2989. p.id_author in (select id_employer from permission where id_boss = :i_id_employer and enabled=1)
  2990. or
  2991. t.id in
  2992. (select distinct g.id_task
  2993. from grouptask g
  2994. join task t on t.id=g.id_task
  2995. where g.id_original in
  2996. (select id_employer from permission where id_boss = :i_id_employer and enabled=1)
  2997. and t.isdeleted=0
  2998. and t.is_checkpoint is null
  2999. and (t.issecret=0 or g.id_task in (select id_task from grouptask where id_original = :i_id_employer)))
  3000. )
  3001. into :O_DEPNAME,
  3002. :O_ID,
  3003. :O_NAME,
  3004. :O_DESCRIPTION,
  3005. :O_STARTDATE,
  3006. :O_ENDDATE
  3007. do
  3008. suspend;
  3009. end
  3010. else
  3011. begin
  3012. for select distinct d.name,
  3013. p.id,
  3014. p.name,
  3015. p.description,
  3016. p.startdate,
  3017. p.enddate
  3018. from project p
  3019. join department d on (p.id_department = d.id)
  3020. left join task t on (p.id = t.id_project)
  3021. where
  3022. p.isdeleted =0
  3023. and p.state = 0
  3024. and p.id_document is null
  3025. and
  3026. (
  3027. p.id_author in (select id_employer from permission where id_boss = :i_id_employer and enabled=1)
  3028. or
  3029. t.id in
  3030. (select distinct g.id_task
  3031. from grouptask g
  3032. join task t on t.id=g.id_task
  3033. where g.id_original in
  3034. (select id_employer from permission where id_boss = :i_id_employer and enabled=1)
  3035. and t.isdeleted=0
  3036. and t.is_checkpoint is null
  3037. and (t.issecret=0 or g.id_task in (select id_task from grouptask where id_original = :i_id_employer)))
  3038. )
  3039. into :O_DEPNAME,
  3040. :O_ID,
  3041. :O_NAME,
  3042. :O_DESCRIPTION,
  3043. :O_STARTDATE,
  3044. :O_ENDDATE
  3045. do
  3046. suspend;
  3047. end
  3048. end^
  3049. Statement failed, SQLCODE = -206
  3050. Dynamic SQL Error
  3051. -SQL error code = -206
  3052. -Column unknown
  3053. -T.IS_CHECKPOINT
  3054. -At line 39, column 20
  3055. At line 5683 in file /tmp/patch_db/script
  3056. SET TERM ; ^
  3057.  
  3058. commit;
  3059.  
  3060. SET TERM ^ ;
  3061. CREATE OR ALTER PROCEDURE GETPROJECTARCHIVE (
  3062. i_id_employer integer)
  3063. returns (
  3064. o_id integer,
  3065. o_name varchar(200),
  3066. o_description varchar(2000),
  3067. o_startdate timestamp,
  3068. o_enddate timestamp,
  3069. o_depname varchar(2000))
  3070. as
  3071. begin
  3072.  
  3073. for select distinct p.id,
  3074. p.name,
  3075. p.description,
  3076. p.startdate,
  3077. p.enddate,
  3078. d.name
  3079. from project p
  3080. join department d on (p.id_department = d.id)
  3081. left join task t on (p.id = t.id_project)
  3082. where
  3083. p.isdeleted =0
  3084. and p.state = 1
  3085. and
  3086. (
  3087. p.id_author in (select id_employer from permission where id_boss = :i_id_employer and enabled=1)
  3088. or
  3089. t.id in
  3090. (select distinct g.id_task
  3091. from grouptask g
  3092. join task t on t.id=g.id_task
  3093. where g.id_original in
  3094. (select id_employer from permission where id_boss = :i_id_employer and enabled=1)
  3095. and t.isdeleted=0
  3096. and t.is_checkpoint is null
  3097. and (t.issecret=0 or g.id_task in (select id_task from grouptask where id_original = :i_id_employer)))
  3098. )
  3099. into :O_ID,
  3100. :O_NAME,
  3101. :O_DESCRIPTION,
  3102. :O_STARTDATE,
  3103. :O_ENDDATE,
  3104. :O_DEPNAME
  3105. do
  3106. suspend;
  3107. end^
  3108. Statement failed, SQLCODE = -206
  3109. Dynamic SQL Error
  3110. -SQL error code = -206
  3111. -Column unknown
  3112. -T.IS_CHECKPOINT
  3113. -At line 36, column 20
  3114. At line 5868 in file /tmp/patch_db/script
  3115. SET TERM ; ^
  3116.  
  3117. commit;
  3118.  
  3119.  
  3120. SET TERM ^ ;
  3121. CREATE OR ALTER PROCEDURE GETNAVIGATIONTREE_PROJ (
  3122. i_id_employer integer,
  3123. i_is_show_archive_projects smallint)
  3124. returns (
  3125. id integer,
  3126. name varchar(200),
  3127. description varchar(2000),
  3128. state smallint,
  3129. color varchar(16),
  3130. is_mark_by_color smallint)
  3131. as
  3132. declare variable l_mydepid integer;
  3133. BEGIN
  3134. select ID_Department from employer where id=:I_ID_EMPLOYER into :L_MYDEPID;
  3135. for select distinct p.id,
  3136. p.name,
  3137. p.description,
  3138. p.state,
  3139. p.color,
  3140. p.is_mark_by_color
  3141. from project p
  3142. left join task t on (p.id = t.id_project)
  3143. where
  3144. p.isdeleted =0
  3145. and (p.state = 0 or p.state = :i_is_show_archive_projects)
  3146. and
  3147. (
  3148. p.id_author in (select id_employer from permission where id_boss = :i_id_employer and enabled=1)
  3149. or
  3150. t.id in
  3151. (select distinct g.id_task
  3152. from grouptask g
  3153. join task t on t.id=g.id_task
  3154. where g.id_original in
  3155. (select id_employer from permission where id_boss = :i_id_employer and enabled=1)
  3156. and t.isdeleted=0
  3157. and t.is_checkpoint is null
  3158. and (t.issecret=0 or g.id_task in (select id_task from grouptask where id_original = :i_id_employer)))
  3159. )
  3160. INTO :ID,
  3161. :NAME,
  3162. :DESCRIPTION,
  3163. :STATE,
  3164. :color,
  3165. :is_mark_by_color
  3166. DO
  3167. BEGIN
  3168. SUSPEND;
  3169. END
  3170. END^
  3171. Statement failed, SQLCODE = -206
  3172. Dynamic SQL Error
  3173. -SQL error code = -206
  3174. -Column unknown
  3175. -T.IS_CHECKPOINT
  3176. -At line 37, column 20
  3177. At line 5975 in file /tmp/patch_db/script
  3178. SET TERM ; ^
  3179.  
  3180. commit;
  3181.  
  3182. /*stasy - prava na proekty conec*/
  3183.  
  3184. /* Добавление домена если такового еще нет.*/
  3185. SET TERM ^ ;
  3186. CREATE OR ALTER PROCEDURE CREATE_DOMAIN_IF_NOT_EXIST (
  3187. domain_name varchar(100),
  3188. sql_param_str varchar(300))
  3189. as
  3190. declare variable is_exist varchar(200);
  3191. BEGIN
  3192. SELECT RDB$FIELD_NAME FROM RDB$FIELDS WHERE UPPER( RDB$FIELD_NAME) = UPPER(:domain_name)
  3193. INTO :is_exist;
  3194.  
  3195. if (is_exist is null) THEN
  3196. BEGIN
  3197. EXECUTE STATEMENT
  3198. 'CREATE DOMAIN ' || UPPER(:domain_name)||' '|| :sql_param_str ;
  3199. END
  3200. END^
  3201. SET TERM ; ^
  3202. commit;
  3203. GRANT EXECUTE ON PROCEDURE CREATE_DOMAIN_IF_NOT_EXIST TO SYSDBA;
  3204. commit;
  3205.  
  3206. /* Создаем новый домен для хранения ЭЦП документов,заменяем тип поля в documents.signature*/
  3207. EXECUTE PROCEDURE CREATE_DOMAIN_IF_NOT_EXIST ('BLOB_4096', 'AS BLOB SUB_TYPE 1 SEGMENT SIZE 4096 CHARACTER SET WIN1251');
  3208. commit;
  3209. update RDB$RELATION_FIELDS set RDB$FIELD_SOURCE = 'BLOB_4096', RDB$COLLATION_ID = 0 where (RDB$FIELD_NAME = 'SIGNATURE') and (RDB$RELATION_NAME = 'DOCUMENTS');
  3210. commit;
  3211.  
  3212. SET TERM ^ ;
  3213.  
  3214. /*меняем строчку в вычислении признака issecretary - не учитывались псевдонимы*/
  3215. create or alter procedure INFORMER2_GETMYTASKS (
  3216. ID_EMPLOYER integer,
  3217. ATASKID integer,
  3218. MINTASKID integer)
  3219. returns (
  3220. TASKID integer,
  3221. TASKNAME varchar(2000),
  3222. ISVIEWED smallint,
  3223. ISGROUP smallint,
  3224. ISNEWMESSAGES smallint,
  3225. AMIAUTHOR smallint,
  3226. PRJID integer,
  3227. ISREPORTED smallint,
  3228. AUTHORID integer,
  3229. EMPID integer,
  3230. ISREJECTED smallint,
  3231. ISWITHREPORT smallint,
  3232. LASTACTID integer,
  3233. TASKDESC varchar(10000),
  3234. STARTDATE timestamp,
  3235. ENDDATE timestamp,
  3236. ACTCOUNT integer,
  3237. ATT varchar(24000),
  3238. TASK_TYPE smallint,
  3239. ORDERTYPE smallint,
  3240. DOCUMENTID integer,
  3241. PRIORITY smallint,
  3242. LASTACTDATE timestamp,
  3243. EMPSID varchar(5000),
  3244. DEPPATH varchar(2000),
  3245. STATE smallint,
  3246. LASTACT varchar(10000),
  3247. LASTACTEMPID integer,
  3248. ISONLYFORVIEW smallint,
  3249. USERID integer,
  3250. MYCOLOR smallint,
  3251. SEND_ACTIONS smallint,
  3252. RECEIVE_MAIL smallint,
  3253. RECEIVE_SMS smallint,
  3254. ACOUNT integer,
  3255. LASTACOUNT integer,
  3256. DOCUMENTNAME varchar(1000),
  3257. DOCUMENTTYPEID integer,
  3258. ISRESOLUTION smallint,
  3259. ID_REALAUTHOR integer,
  3260. ID_TASKINITIATOR integer,
  3261. DOCVERSION integer,
  3262. BTN varchar(200),
  3263. PARENTID integer,
  3264. SHOWDATE timestamp,
  3265. IDFOLDER integer,
  3266. ISSECRETARY smallint,
  3267. ISCONTROL smallint,
  3268. CTRLSID varchar(2000),
  3269. SIGNSID varchar(2000),
  3270. IS_HAVE_ISOLATED smallint,
  3271. SYSACTCOUNT integer,
  3272. MEANSACTCOUNT integer,
  3273. ID_CHECKPOINT integer,
  3274. ID_META_DICTIONARY integer,
  3275. NRECORD_TASKTYPE integer,
  3276. AUTHORSID varchar(2000),
  3277. MAINEMPSID varchar(2000),
  3278. NUMERATOR varchar(100),
  3279. ISSECRET smallint,
  3280. NEWACTCOUNT integer,
  3281. IS_COMMITED smallint,
  3282. CTRLID integer,
  3283. ID_LAST_VIEWED_ACT integer,
  3284. LASTCHANGE timestamp,
  3285. ISUSEPARENTDOCS smallint,
  3286. IS_SHOW_TASK smallint)
  3287. as
  3288. declare variable GT_LASTCHANGE timestamp;
  3289. declare variable TA_LASTCHANGE timestamp;
  3290. declare variable I integer;
  3291. declare variable CNT integer;
  3292. declare variable EXECDOCUMENTID varchar(1000);
  3293. declare variable L_ISHIDDEN integer;
  3294. declare variable SID integer;
  3295. begin
  3296. for select TASKID, TASKNAME, ISGROUP,
  3297. AMIAUTHOR, PRJID, IsReported,
  3298. /* AuthorId, EmpId, */IsRejected, IsWithReport,
  3299. taskdesc, startdate, enddate, task_type,
  3300. documentid, priority, deppath, state, IsOnlyForView, UserId, Send_Actions,
  3301. ExecDocumentId, ID_REALAUTHOR, ID_TASKINITIATOR, PARENTID, is_have_isolated, id_checkpoint
  3302. , id_meta_dictionary, nrecord_tasktype,numerator
  3303. from Informer2_Getmytasks1(:ID_EMPLOYER, :ATASKID)
  3304. into :TASKID, :TASKNAME, :ISGROUP,
  3305. :AMIAUTHOR, :PRJID, :IsReported,
  3306. /* :AuthorId, :EmpId,*/ :IsRejected, :IsWithReport,
  3307. :taskdesc, :startdate, :enddate, :task_type,
  3308. :documentid, :priority, :deppath, :state, :IsOnlyForView, :UserId, :Send_Actions,
  3309. :ExecDocumentId, :ID_REALAUTHOR, :ID_TASKINITIATOR,:PARENTID, :is_have_isolated, :id_checkpoint
  3310. ,:id_meta_dictionary, :nrecord_tasktype,:numerator
  3311. do
  3312. if (TaskId=ATaskId or TaskId>MinTaskId)
  3313. then begin
  3314. if (DocumentId is null and ExecDocumentId is null) then OrderType=0;
  3315. else
  3316. if (DocumentId is not null) then OrderType=1;
  3317. else
  3318. if (ExecDocumentId is not null)
  3319. then begin
  3320. OrderType=2;
  3321. DocumentId=ExecDocumentId;
  3322. end
  3323. ISNEWMESSAGES=0;
  3324. EXECUTE PROCEDURE informer2_gettaskids(ID_EMPLOYER, TASKID, IsOnlyForView) returning_values :EMPSID, :CTRLSID, :SIGNSID,
  3325. :AuthorId, :EmpId , :AUTHORSID , :MAINEMPSID, :CTRLID;
  3326. LastActDate=NULL;
  3327. LastActId=-1;
  3328. LastActId=-1;
  3329. ActCount=0;
  3330. LASTACT='';
  3331. LASTACTEMPID=-1;
  3332. idfolder=0;
  3333. newactcount=0;
  3334. MyColor=NULL;
  3335. cnt=NULL;
  3336. select ta.marker_color, ta.count_actions_view, ta.is_view_new_actions, ta.Id_last_viewed_action
  3337. from task_attributes ta
  3338. where ta.id_employer=:id_employer and
  3339. ta.id_task=:taskid
  3340. into :mycolor, :cnt, :ISNEWMESSAGES, :Id_last_viewed_act;
  3341. select o_result
  3342. from CheckTaskViewed(:ID_EMPLOYER, :taskid)
  3343. into :isviewed;
  3344. select t.la_id, t.action_count, t.sysaction_count, t.meansaction_count, t.issecret, t.isuseparentdocs
  3345. from Task t
  3346. where id= :TaskId
  3347. into :LastActId, :ActCount, :sysactcount, :meansactcount, :issecret, :isuseparentdocs;
  3348. if (isuseparentdocs=1) then
  3349. begin
  3350. SELECT O_DocumentID, O_DocumentName FROM getparentdocs(:TaskID)
  3351. into :Documentid, :Documentname;
  3352. end
  3353. if (ActCount is null) then ActCount=0;
  3354. ACount=ActCount;
  3355. if ((ISNEWMESSAGES=1)or(ISNEWMESSAGES is null)or :ActCount=0)
  3356. then ISNEWMESSAGES=0;
  3357. else ISNEWMESSAGES=1;
  3358. if (LastActId is null) then LastActId=0;
  3359. if (LastActId>0) then
  3360. begin
  3361. select adate, Name, ID_Employer
  3362. from Actions
  3363. where id= :LastActId
  3364. into :LastActDate, :LASTACT, :LASTACTEMPID;
  3365. end
  3366. execute procedure Informer2_TaskAtt(:taskid, -1, -1)
  3367. returning_values :att;
  3368.  
  3369. if (MyColor is null) then MyColor=0;
  3370. select O_RECIVE_SMS, O_RECIVE_MAIL
  3371. from GET_TASK_MAIL_SMS(:TaskId, :id_employer)
  3372. into :receive_sms, :receive_mail;
  3373.  
  3374. if (cnt is null) then lastacount=0;
  3375. else lastacount=cnt;
  3376. newactcount=acount-lastacount;
  3377. isresolution=null;
  3378. btn=null;
  3379. select first 1 rt.isresolution, rt.button_caption from routetrees rt
  3380. where rt.id_task = :taskid and
  3381. rt.isvirtual = 0 and
  3382. rt.isdeleted = 0 and
  3383. (exists(select id from routenode rn
  3384. where rn.id_routetree = rt.id and
  3385. rn.id_employer = :id_employer and
  3386. rn.isdeleted = 0))
  3387. into :isresolution, :btn;
  3388. if (isresolution is null) then isresolution=0;
  3389. DocumentName='';
  3390. DocumentTypeId=NULL;
  3391. DocVersion=NULL;
  3392. select Field1, ID_DocType, Doc_Version
  3393. from Documents
  3394. where id= :DocumentId
  3395. into :DocumentName, :DocumentTypeId, :DocVersion;
  3396. i=1;
  3397. if (OrderType=1) then
  3398. begin
  3399. select O_result from documentcommited (:id_employer, :taskid)
  3400. into :is_commited;
  3401. if (is_commited=1) then
  3402. if (not (exists(select first 1 id_task from grouptask where id_task=:TaskId and
  3403. id_employer=:ID_employer and is_controler=1)))
  3404. then i=0;
  3405. end
  3406. else is_commited=0;
  3407. if (IsOnlyForView is null) then IsOnlyForView=0;
  3408. if (IsOnlyForView=1) then
  3409. begin
  3410. /* SignsId=''; */
  3411. if (exists (select first 1 id
  3412. from Actions
  3413. where id_task=:TaskId and
  3414. examinated=1 and
  3415. (id_employer= :id_employer or id_employer in (select O_EMPLOYERID from
  3416.  
  3417. GETEMPLOYERALIASES(:id_employer)))
  3418. ))
  3419. then i=0;
  3420. else begin
  3421. i=1;
  3422. end
  3423. end
  3424. /*if user needs information by the only one task,
  3425. then return this task in any case*/
  3426. if ((i=0) and (ATASKID<>-1)) then i=1;
  3427. if (i=1) then
  3428. begin
  3429. showdate=NULL;
  3430. select gt.show_task_date
  3431. from grouptask gt
  3432. where gt.id_task=:taskid and gt.id_employer=:id_employer
  3433. into :showdate;
  3434.  
  3435. ISSECRETARY=0;
  3436. if (exists(select * from grouptask gr where gr.id_task=:TaskId
  3437. AND GR.id_original=:id_employer and gr.is_shadow=1)) then
  3438. ISSECRETARY=1;
  3439. --повесит пережитком
  3440. ISCONTROL=0;
  3441.  
  3442. SELECT
  3443. t.lastchange,
  3444. ta.lastchange,
  3445. gt.lastchange
  3446. FROM
  3447. task t
  3448. left join task_attributes ta on (ta.id_task = t.id and ta.id_employer = :id_employer)
  3449. left join grouptask gt on (gt.id_task = t.id and gt.id_employer = :id_employer)
  3450. WHERE
  3451. t.id = :taskid
  3452. INTO
  3453. :lastchange,
  3454. :ta_lastchange,
  3455. :gt_lastchange;
  3456.  
  3457. if (:ta_lastchange > :lastchange) then
  3458. begin
  3459. lastchange = :ta_lastchange;
  3460. end
  3461.  
  3462. if (:gt_lastchange > :lastchange) then
  3463. begin
  3464. lastchange = :gt_lastchange;
  3465. end
  3466.  
  3467. is_show_task = 0;
  3468.  
  3469. if (is_show_task = 0) then
  3470. begin
  3471.  
  3472. if (exists ( select
  3473. first (1) gt.id_task
  3474. from
  3475. grouptask gt
  3476. where
  3477. gt.id_task = :taskid and
  3478. (
  3479. gt.id_original = :id_employer OR
  3480. gt.id_original = (select parentid from employer where id = :id_employer)
  3481. )
  3482. and
  3483. (
  3484. gt.is_author = 1 OR
  3485. gt.is_respperson = 1 OR
  3486. gt.is_worker = 1 OR
  3487. gt.is_controler = 1 OR
  3488. gt.is_shadow = 1
  3489. )
  3490. )
  3491. )
  3492. then
  3493. is_show_task = 1;
  3494.  
  3495.  
  3496. if (is_show_task = 1) then
  3497. if (exists( select
  3498. first (1) gt.id_task
  3499. from
  3500. grouptask gt
  3501. join task t on
  3502. t.id = gt.id_task
  3503. where
  3504. gt.id_task = :taskid and
  3505. t.is_isolated = 1 and
  3506. (
  3507. gt.id_original = :id_employer OR
  3508. gt.id_original = (select parentid from employer where id = :id_employer)
  3509. )
  3510. and
  3511. (
  3512. gt.is_author = 1 OR
  3513. gt.is_respperson = 1 OR
  3514. gt.is_worker = 1 OR
  3515. gt.is_controler = 1 OR
  3516. gt.is_shadow = 1
  3517. )
  3518. and exists
  3519. (
  3520. select
  3521. first (1) id_task
  3522. from
  3523. grouptask
  3524. where
  3525. id_task = (select parentid from task where id = :taskid) and
  3526. (
  3527. id_original = :id_employer OR
  3528. id_original = (select parentid from employer where id = :id_employer)
  3529. )
  3530. and
  3531. (
  3532. is_author = 1 OR
  3533. is_respperson = 1 OR
  3534. is_worker = 1 OR
  3535. is_controler = 1 OR
  3536. is_shadow = 1
  3537. )
  3538. )
  3539. )
  3540. )
  3541. then
  3542. is_show_task = 0;
  3543.  
  3544. end
  3545.  
  3546. suspend;
  3547. end
  3548. end
  3549. end^
  3550.  
  3551. SET TERM ; ^
  3552.  
  3553. commit;INSERT INTO SETTINGS (SETTINGS_KEY,SETTINGS_VALUE) VALUES ('version','1.4.18');
  3554.  
  3555. update patch_info
  3556. set paramvalue = 'OK'
  3557. where paramname = 'PATCH_STATUS';
  3558. update patch_info
  3559. set paramvalue = '1.4.18'
  3560. where paramname = 'CURRENT_VERSION';
  3561. commit work;
  3562.  
  3563.  
  3564. commit;
  3565. commit work;
  3566.  
  3567. Use CONNECT or CREATE DATABASE to specify a database
  3568. CONNECT "/var/Motiw/db/motiw.fdb" USER 'SYSDBA' PASSWORD 'masterkey';
  3569.  
  3570. SET NAMES WIN1251;
  3571.  
  3572. update patch_info
  3573. set paramvalue = 'Updates to 1.4.18'
  3574. where paramname = 'PATCH_STATUS';
  3575. update patch_info
  3576. set paramvalue = cast(paramvalue as integer) + 1
  3577. where paramname = 'PATCH_STEP';
  3578. SET GENERATOR gen_patch_percent to 0;
  3579. COMMIT WORK;
  3580. /*-----------------------------------------------------------------------------------------------------------------------*/
  3581. /* Ну и по традиции тут удаляем хлам и пережитки прошлой жизни */
  3582. /*-----------------------------------------------------------------------------------------------------------------------*/
  3583. SET TERM ^ ;
  3584. CREATE OR ALTER PROCEDURE TMP_DROP_XLAM
  3585. AS
  3586. declare variable is_exist smallint;
  3587. BEGIN
  3588. SELECT result FROM IS_PROCEDURE_EXISTS('GETPERMREE_FOR_EMPLOYER_DOCINIT')
  3589. INTO :is_exist;
  3590.  
  3591. IF (is_exist = 1) THEN
  3592. begin
  3593. EXECUTE STATEMENT
  3594. 'DROP PROCEDURE GETPERMREE_FOR_EMPLOYER_DOCINIT;';
  3595. end
  3596.  
  3597. SELECT result FROM IS_PROCEDURE_EXISTS('GETOPENTASKSFORREPORT4')
  3598. INTO :is_exist;
  3599.  
  3600. IF (is_exist = 1) THEN
  3601. begin
  3602. EXECUTE STATEMENT
  3603. 'DROP PROCEDURE GETOPENTASKSFORREPORT4;';
  3604. end
  3605.  
  3606. SELECT result FROM IS_PROCEDURE_EXISTS('GETALLNOTICES')
  3607. INTO :is_exist;
  3608.  
  3609. IF (is_exist = 1) THEN
  3610. begin
  3611. EXECUTE STATEMENT
  3612. 'DROP PROCEDURE GETALLNOTICES;';
  3613. end
  3614. END ^
  3615. SET TERM ; ^
  3616. commit;
  3617.  
  3618. EXECUTE PROCEDURE TMP_DROP_XLAM;
  3619. commit;
  3620. DROP PROCEDURE TMP_DROP_XLAM;
  3621. commit;
  3622.  
  3623. /* добавляем шаблон задачи по умолчанию */
  3624. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('EMPLOYER', 'TASK_TEMPLATE_DEFAULT', 'INTEGER');
  3625.  
  3626. RESULT
  3627. =======
  3628. 1
  3629.  
  3630. commit;
  3631.  
  3632. /* право на создание задач (для проверки доступности кнопки создания задачи) */
  3633. update menuitems set right_kind = 23
  3634. where item_id = 101;
  3635. commit;
  3636.  
  3637. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('EMPLOYER', 'CAN_ADD_TASK', 'SMALLINT');
  3638.  
  3639. RESULT
  3640. =======
  3641. 1
  3642.  
  3643. commit;
  3644.  
  3645. update employer set can_add_task = 1
  3646. where can_add_task is null;
  3647. commit;
  3648.  
  3649. /*---------------------------------------------------------------------------------------*/
  3650. /* stasy: Группы пользователей*/
  3651. /*---------------------------------------------------------------------------------------*/
  3652. /* Создаем таблицу EMP_GROUPS */
  3653. SET TERM ^ ;
  3654. CREATE OR ALTER PROCEDURE TMP_EMP_GROUPS_CREATE
  3655. AS
  3656. declare variable is_exist smallint;
  3657. BEGIN
  3658. /* Гарантируем генератор */
  3659. SELECT result FROM IS_GENERATOR_EXISTS('GEN_EMP_GROUPS_ID')
  3660. INTO :is_exist;
  3661.  
  3662. IF (is_exist = 0) THEN
  3663. BEGIN
  3664. EXECUTE STATEMENT
  3665. 'CREATE GENERATOR GEN_EMP_GROUPS_ID';
  3666. END
  3667.  
  3668. /* Гарантируем таблицу */
  3669. SELECT result FROM IS_TABLE_EXISTS('EMP_GROUPS')
  3670. INTO :is_exist;
  3671.  
  3672. IF (is_exist = 0) THEN
  3673. BEGIN
  3674. EXECUTE STATEMENT
  3675. 'CREATE TABLE EMP_GROUPS (
  3676. ID_GROUP INTEGER NOT NULL,
  3677. TITLE VARCHAR(200) NOT NULL,
  3678. DISCRIPTION VARCHAR(1000),
  3679. IS_DELITED SMALLINT,
  3680. ID_OWNER INTEGER NOT NULL,
  3681. iscommon SMALLINT,
  3682. constraint PK_EMP_GROUPS_ID primary key (ID_GROUP))';
  3683. END
  3684. END ^
  3685. SET TERM ; ^
  3686. commit;
  3687. EXECUTE PROCEDURE TMP_EMP_GROUPS_CREATE;
  3688. commit;
  3689. DROP PROCEDURE TMP_EMP_GROUPS_CREATE;
  3690. commit;
  3691.  
  3692. /* Создаем триггер для генерации ID */
  3693. SET TERM ^;
  3694. CREATE OR ALTER TRIGGER EMP_GROUPS_BI_GEN_ID
  3695. FOR EMP_GROUPS
  3696. ACTIVE BEFORE INSERT
  3697. AS
  3698. BEGIN
  3699. IF (NEW.ID_GROUP IS NULL) THEN
  3700. NEW.ID_GROUP = GEN_ID(GEN_EMP_GROUPS_ID, 1);
  3701. END^
  3702. SET TERM ; ^
  3703. commit;
  3704.  
  3705. /* раздаем гранты на таблицу */
  3706. EXECUTE PROCEDURE GIVE_GRANTS_TO_ALL('TABLE','EMP_GROUPS','ALL');
  3707. commit;
  3708.  
  3709. /* Таблица EMPLOUEROFGROUP */
  3710.  
  3711. /* Создаем таблицу EMPLOUEROFGROUP для связки таблиц EMP_GROUPS и employer (пользователь может находиться в нескольких группах) */
  3712. SET TERM ^ ;
  3713. CREATE OR ALTER PROCEDURE TMP_EMPLOYEROFGROUP_CREATE
  3714. AS
  3715. declare variable is_exist smallint;
  3716. BEGIN
  3717. /* Гарантируем таблицу */
  3718. SELECT result FROM IS_TABLE_EXISTS('EMPLOYEROFGROUP')
  3719. INTO :is_exist;
  3720.  
  3721. IF (is_exist = 0) THEN
  3722. BEGIN
  3723. EXECUTE STATEMENT
  3724. 'CREATE TABLE EMPLOYEROFGROUP (
  3725. ID_EMP INTEGER NOT NULL,
  3726. ID_GROUP INTEGER NOT NULL,
  3727. PERMITION SMALLINT,
  3728. IS_DELITED SMALLINT,
  3729. constraint PK_EMPLOYEROFGROUP primary key (ID_EMP, ID_GROUP))';
  3730. END
  3731. END ^
  3732. SET TERM ; ^
  3733. commit;
  3734. EXECUTE PROCEDURE TMP_EMPLOYEROFGROUP_CREATE;
  3735. commit;
  3736. DROP PROCEDURE TMP_EMPLOYEROFGROUP_CREATE;
  3737. commit;
  3738.  
  3739. /* раздаем гранты на таблицу */
  3740. EXECUTE PROCEDURE GIVE_GRANTS_TO_ALL('TABLE','EMPLOYEROFGROUP','ALL');
  3741. commit;
  3742.  
  3743. /*создаем пункт меню группы пользователей*/
  3744.  
  3745. EXECUTE PROCEDURE ADDMENUITEMBYTAG(868, 'L_GLOBAL_PERMISSIONS_GROUP', '/user/empgroup/', 'L_MENU_ADMINISTRATION', 8, 1, 6, NULL);
  3746. commit;
  3747.  
  3748. /*добавляем право на группы пользователей*/
  3749.  
  3750. SET TERM ^ ;
  3751.  
  3752. CREATE OR ALTER PROCEDURE GET_RIGHTS_OF_GROUP (
  3753. i_id_employer integer,
  3754. i_id_groupright integer)
  3755. returns (
  3756. o_right_kind integer,
  3757. o_id_object integer,
  3758. o_objectname varchar(1000),
  3759. o_group_has_right smallint,
  3760. o_can_edit smallint)
  3761. as
  3762. declare variable l_id_owner integer;
  3763. declare variable l_id_groupright integer;
  3764. begin
  3765.  
  3766. O_ID_OBJECT = 0;
  3767. O_OBJECTNAME = '';
  3768. for select gl.id
  3769. from grouprights_list gl
  3770. into :O_RIGHT_KIND
  3771. do
  3772. begin
  3773. select o_result from get_right_employer_and_group(:i_id_employer,:o_right_kind,0)
  3774. into :o_can_edit;
  3775.  
  3776. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  3777. into :o_group_has_right;
  3778. suspend;
  3779. end
  3780.  
  3781. for select dt.id, dt.name, dt.id_owner from doctypes dt
  3782. where dt.isdeleted=0
  3783. into :o_id_object, :o_objectname, :l_id_owner
  3784. do
  3785. begin
  3786. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  3787. o_can_edit = 1;
  3788. else
  3789. o_can_edit = 0;
  3790. o_right_kind = 1;
  3791. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  3792. into :o_group_has_right;
  3793. suspend;
  3794. o_right_kind = 2;
  3795. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  3796. into :o_group_has_right;
  3797. suspend;
  3798. o_right_kind = 28; /* 28 - право выбора связанных документов */
  3799. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  3800. into :o_group_has_right;
  3801. suspend;
  3802. end
  3803.  
  3804. o_right_kind = 3;
  3805. for select rt.id, rt.name, rt.id_owner from routetemplate rt
  3806. where rt.isdeleted=0 and rt.kind=0
  3807. into :o_id_object, :o_objectname, :l_id_owner
  3808. do
  3809. begin
  3810. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  3811. o_can_edit = 1;
  3812. else
  3813. o_can_edit = 0;
  3814. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  3815. into :o_group_has_right;
  3816. suspend;
  3817. end
  3818.  
  3819. o_right_kind = 9;
  3820. for select fd.id, fd.name, fd.id_owner from fdoctemplate fd
  3821. where fd.isdeleted=0
  3822. into :o_id_object, :o_objectname, :l_id_owner
  3823. do
  3824. begin
  3825. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  3826. o_can_edit = 1;
  3827. else
  3828. o_can_edit = 0;
  3829. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  3830. into :o_group_has_right;
  3831. suspend;
  3832. end
  3833.  
  3834. o_right_kind = 12;
  3835. for select it.id, it.name, it.id_owner from iwgtemplate it
  3836. where it.isdeleted=0
  3837. into :o_id_object, :o_objectname, :l_id_owner
  3838. do
  3839. begin
  3840. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  3841. o_can_edit = 1;
  3842. else
  3843. o_can_edit = 0;
  3844. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  3845. into :o_group_has_right;
  3846. suspend;
  3847. end
  3848.  
  3849. o_right_kind = 10;
  3850. if (I_ID_GROUPRIGHT is null) then L_ID_GROUPRIGHT=0;
  3851. else
  3852. L_ID_GROUPRIGHT=:I_ID_GROUPRIGHT;
  3853. for select g.id, g.name, g.id_owner from grouprights g
  3854. where g.isdeleted=0 and g.isvisible=1 and g.id<>:L_ID_GROUPRIGHT
  3855. into :o_id_object, :o_objectname, :l_id_owner
  3856. do
  3857. begin
  3858. if (l_id_owner=i_id_employer ) then
  3859. o_can_edit = 1;
  3860. else
  3861. o_can_edit = 0;
  3862. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  3863. into :o_group_has_right;
  3864. suspend;
  3865. end
  3866. o_right_kind = 15;
  3867. o_can_edit = 1;
  3868. for select md.id, md.name, md.id_owner
  3869. from meta_dictionary md
  3870. where md.isdeleted=0 and md.id_owner=:i_id_employer and recordtype=1
  3871. into :o_id_object, :o_objectname, :l_id_owner
  3872. do
  3873. begin
  3874. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  3875. into :o_group_has_right;
  3876. suspend;
  3877. end
  3878. /* 17 права на просмотр записей в справочнике */
  3879. /* 18 права на добавление записей в справочник */
  3880. /* 19 права на изменение записей в справочнике */
  3881. /* 20 права на удаление записей в справочнике */
  3882. o_can_edit = 1;
  3883. for select md.id, md.name, md.id_owner
  3884. from meta_dictionary md
  3885. where md.isdeleted=0 and md.id_owner=:i_id_employer and recordtype=0
  3886. into :o_id_object, :o_objectname, :l_id_owner
  3887. do
  3888. begin
  3889. o_right_kind = 17;
  3890. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  3891. into :o_group_has_right;
  3892. suspend;
  3893. o_right_kind = 18;
  3894. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  3895. into :o_group_has_right;
  3896. suspend;
  3897. o_right_kind = 19;
  3898. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  3899. into :o_group_has_right;
  3900. suspend;
  3901. o_right_kind = 20;
  3902. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  3903. into :o_group_has_right;
  3904. suspend;
  3905. end
  3906. o_right_kind = 22;
  3907. for select tt.id, tt.name, tt.id_owner from task_templates tt
  3908. into :o_id_object, :o_objectname, :l_id_owner
  3909. do
  3910. begin
  3911. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  3912. o_can_edit = 1;
  3913. else
  3914. o_can_edit = 0;
  3915. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  3916. into :o_group_has_right;
  3917. suspend;
  3918. end
  3919. -- плагины не привязвнные к типам
  3920. o_right_kind = 77;
  3921. for select plg.id, plg.name, plg.id_owner from plugins plg where plg.no_connect_to_type=1
  3922. into :o_id_object, :o_objectname, :l_id_owner
  3923. do
  3924. begin
  3925. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  3926. o_can_edit = 1;
  3927. else
  3928. o_can_edit = 0;
  3929. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  3930. into :o_group_has_right;
  3931. suspend;
  3932. end
  3933. /* 23 права на просмотр событий календаря */
  3934. /* 24 права на добавление и редактирование событий в календарь */
  3935. /* 25 полные права*/
  3936. o_can_edit = 1;
  3937. for select c.id, c.name, c.id_owner
  3938. from calendars c
  3939. where c.id_owner=:i_id_employer and is_system=0
  3940. into :o_id_object, :o_objectname, :l_id_owner
  3941. do
  3942. begin
  3943. o_right_kind = 23;
  3944. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  3945. into :o_group_has_right;
  3946. suspend;
  3947. o_right_kind = 24;
  3948. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  3949. into :o_group_has_right;
  3950. suspend;
  3951. o_right_kind = 25;
  3952. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  3953. into :o_group_has_right;
  3954. suspend;
  3955. end
  3956. o_right_kind = 26;
  3957. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,0)
  3958. into :o_group_has_right;
  3959. suspend;
  3960.  
  3961. /* 27 права на общедоступные группы внешних пользователей */
  3962. for select eeg.id, eeg.name, eeg.id_owner from email_employer_group eeg
  3963. where eeg.isdeleted=0 and eeg.iscommon=1
  3964. into :o_id_object, :o_objectname, :l_id_owner
  3965. do
  3966. begin
  3967. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  3968. o_can_edit = 1;
  3969. else
  3970. o_can_edit = 0;
  3971. o_right_kind = 27;
  3972. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  3973. into :o_group_has_right;
  3974. suspend;
  3975. end
  3976.  
  3977. /* 29 - права на группы пользователей*/
  3978.  
  3979. for select eeg.id_group, eeg.title, eeg.id_owner from EMP_GROUPS eeg
  3980. where eeg.IS_DELITED=0
  3981. into :o_id_object, :o_objectname, :l_id_owner
  3982. do
  3983. begin
  3984. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  3985. o_can_edit = 1;
  3986. else
  3987. o_can_edit = 0;
  3988. o_right_kind = 29;
  3989. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  3990. into :o_group_has_right;
  3991. suspend;
  3992.  
  3993. end
  3994.  
  3995. end^
  3996.  
  3997. SET TERM ; ^
  3998. COMMIT;
  3999.  
  4000. /*процедура возвращает системные права пользователей - так, как если бы он создавался
  4001. ** сотрудник - полное право на себя
  4002. ** начальник - полное право на свой отдел и подчиненные
  4003. ** - только свои задачи на начальников и делопроизводителей одного уровня
  4004. ** делопроиз - только свои задачи на свой отдел и подчиненные
  4005. ** - начальников и делопроизводителей одного уровня*/
  4006.  
  4007. SET TERM ^ ;
  4008.  
  4009. CREATE OR ALTER PROCEDURE GET_SISTEM_PERM (
  4010. i_id integer)
  4011. returns (
  4012. o_emp integer,
  4013. o_right integer)
  4014. as
  4015. declare variable l_boss integer;
  4016. declare variable l_depid integer;
  4017. declare variable l_empid integer;
  4018. declare variable l_isboss integer;
  4019. declare variable l_mydepid integer;
  4020. declare variable l_myparentdepid integer;
  4021. declare variable l_parentdepid integer;
  4022. BEGIN
  4023. /*проверяем кем является чувак и выбираем его подразделение*/
  4024. select e.isboss, e.id_department from employer e where e.id = :i_id
  4025. into :l_boss, :L_MYDEPID;
  4026. if (:l_boss = 0) then exit;/*если просто сотрудник - то выходим*/
  4027. /*получаем родительское подразделение*/
  4028. select parentid from department
  4029. where id = :L_MYDEPID
  4030. into :L_MYPARENTDEPID;
  4031. /*получаем подразделение "для начальника"*/
  4032. for select O_ID
  4033. from GETTREE_FOR_BOSS (:i_id)
  4034. into :L_DEPID
  4035. do
  4036. begin
  4037. /*находим подразделения одного уровня*/
  4038. select parentid
  4039. from department
  4040. where id=:L_DEPID
  4041. into :L_PARENTDEPID;
  4042. /*и проверяем там каждого сотрудника*/
  4043. for select id, isboss
  4044. from employer
  4045. where isdeleted = 0 and
  4046. id_department = :L_DEPID
  4047. into :o_emp, :L_ISBOSS
  4048. do
  4049. begin /*если оного уровня, но не свое подразделения*/
  4050. if ((:L_MYPARENTDEPID = :L_PARENTDEPID) and
  4051. (:L_ISBOSS > 0) and
  4052. (:L_DEPID <> :L_MYDEPID)) then
  4053. begin/*тогда только свои задачи для начальников*/
  4054. o_right = 2;
  4055. suspend;
  4056. end
  4057.  
  4058. else /*если свое подразделение*/
  4059. begin
  4060. if ((:L_MYPARENTDEPID <> :L_PARENTDEPID) or (:L_DEPID = :L_MYDEPID) ) then
  4061. begin
  4062. if (:l_boss = 1) then
  4063. begin
  4064. o_right = 1;
  4065. suspend;
  4066. end
  4067. else
  4068. begin
  4069. o_right = 2;
  4070. suspend;
  4071. end
  4072. end
  4073. end
  4074. end
  4075.  
  4076. end
  4077. END^
  4078.  
  4079. SET TERM ; ^
  4080. COMMIT;
  4081.  
  4082. /*---------------------------------------------------------------------------------------*/
  4083. /* stasy: Группы пользователей - конец*/
  4084. /*---------------------------------------------------------------------------------------*/
  4085. /*---------------------------------------------------------------------------------------*/
  4086. /* stasy: Задания по событиям - начало*/
  4087. /*---------------------------------------------------------------------------------------*/
  4088. /* 1.1 Создаем таблицу EVENTS_TYPES, в ней будет id события и тег */
  4089. /*---------------------------------------------------------------------------------------*/
  4090. SET TERM ^ ;
  4091. CREATE OR ALTER PROCEDURE TMP_JOBS_TYPES_CREATE
  4092. AS
  4093. declare variable is_exist smallint;
  4094. BEGIN
  4095. /* Гарантируем таблицу */
  4096. SELECT result FROM IS_TABLE_EXISTS('JOBS_TYPES')
  4097. INTO :is_exist;
  4098.  
  4099. IF (is_exist = 0) THEN
  4100. BEGIN
  4101. EXECUTE STATEMENT
  4102. 'CREATE TABLE JOBS_TYPES (
  4103. ID_TYPE INTEGER NOT NULL,
  4104. TYPE_NAME VARCHAR(200) NOT NULL,
  4105. constraint PK_JOBS_TYPES primary key (ID_TYPE))';
  4106. END
  4107. END ^
  4108. SET TERM ; ^
  4109. commit;
  4110. EXECUTE PROCEDURE TMP_JOBS_TYPES_CREATE;
  4111. commit;
  4112. DROP PROCEDURE TMP_JOBS_TYPES_CREATE;
  4113. commit;
  4114. /*---------------------------------------------------------------------------------------*/
  4115. /* 1.2 раздаем гранты на таблицу */
  4116. /*---------------------------------------------------------------------------------------*/
  4117. EXECUTE PROCEDURE GIVE_GRANTS_TO_ALL('TABLE','JOBS_TYPES','ALL');
  4118. commit;
  4119. /*---------------------------------------------------------------------------------------*/
  4120. /* 1.3 к этому моменту в ней будет одно значение - "создать подзадачу по шаблону"*/
  4121. /*---------------------------------------------------------------------------------------*/
  4122. SET TERM ^ ;
  4123. CREATE OR ALTER PROCEDURE TMP_JOBS_TYPES_INSERT
  4124. AS
  4125. declare variable is_exist smallint;
  4126. BEGIN
  4127. /*если еще пустая*/
  4128. SELECT count(*) from JOBS_TYPES
  4129. INTO :is_exist;
  4130.  
  4131. IF (is_exist = 0) THEN
  4132. BEGIN
  4133. INSERT INTO JOBS_TYPES (ID_TYPE, TYPE_NAME) VALUES (1, 'L_SUB_TASK_BY_TEMPL');
  4134. END
  4135. END ^
  4136. SET TERM ; ^
  4137. commit;
  4138. EXECUTE PROCEDURE TMP_JOBS_TYPES_INSERT;
  4139. commit;
  4140. DROP PROCEDURE TMP_JOBS_TYPES_INSERT;
  4141. commit;
  4142.  
  4143. /*---------------------------------------------------------------------------------------*/
  4144. /* 2.1 Создаем таблицу jobs, в ней будет: локальный id, тип задания и ид задания */
  4145. /*---------------------------------------------------------------------------------------*/
  4146. SET TERM ^ ;
  4147. CREATE OR ALTER PROCEDURE TMP_JOBS_CREATE
  4148. AS
  4149. declare variable is_exist smallint;
  4150. BEGIN
  4151.  
  4152. /* Гарантируем генератор */
  4153. SELECT result FROM IS_GENERATOR_EXISTS('GEN_JOB_ID')
  4154. INTO :is_exist;
  4155.  
  4156. IF (is_exist = 0) THEN
  4157. BEGIN
  4158. EXECUTE STATEMENT
  4159. 'CREATE GENERATOR GEN_JOB_ID';
  4160. END
  4161.  
  4162. /* Гарантируем таблицу */
  4163. SELECT result FROM IS_TABLE_EXISTS('JOBS')
  4164. INTO :is_exist;
  4165.  
  4166. IF (is_exist = 0) THEN
  4167. BEGIN
  4168. EXECUTE STATEMENT
  4169. 'CREATE TABLE JOBS (
  4170. ID_JOB_LIST INTEGER,
  4171. ID_JOB INTEGER NOT NULL,
  4172. ID_JOB_TYPE INTEGER NOT NULL,
  4173. constraint PK_JOBS primary key (ID_JOB))';
  4174. END
  4175. END ^
  4176. SET TERM ; ^
  4177. commit;
  4178. EXECUTE PROCEDURE TMP_JOBS_CREATE;
  4179. commit;
  4180. DROP PROCEDURE TMP_JOBS_CREATE;
  4181. commit;
  4182. /*---------------------------------------------------------------------------------------*/
  4183. /* 2.2 Создаем триггер для генерации ID */
  4184. /*---------------------------------------------------------------------------------------*/
  4185. SET TERM ^;
  4186. CREATE OR ALTER TRIGGER JOB_BI_GEN_ID
  4187. FOR JOBS
  4188. ACTIVE BEFORE INSERT
  4189. AS
  4190. BEGIN
  4191. IF (NEW.ID_JOB IS NULL) THEN
  4192. NEW.ID_JOB = GEN_ID(GEN_JOB_ID, 1);
  4193. END^
  4194. SET TERM ; ^
  4195. commit;
  4196. /*---------------------------------------------------------------------------------------*/
  4197. /* 2.3 раздаем гранты на таблицу */
  4198. /*---------------------------------------------------------------------------------------*/
  4199. EXECUTE PROCEDURE GIVE_GRANTS_TO_ALL('TABLE','JOBS','ALL');
  4200. commit;
  4201. /*---------------------------------------------------------------------------------------*/
  4202. /* 3.1 Создаем таблицу job_list, в ней будет: ид из Joba и из связки */
  4203. /*---------------------------------------------------------------------------------------*/
  4204. SET TERM ^ ;
  4205. CREATE OR ALTER PROCEDURE TMP_JOB_LIST_CREATE
  4206. AS
  4207. declare variable is_exist smallint;
  4208. BEGIN
  4209.  
  4210. /* Гарантируем генератор */
  4211. SELECT result FROM IS_GENERATOR_EXISTS('GEN_JOB_LIST_ID')
  4212. INTO :is_exist;
  4213.  
  4214. IF (is_exist = 0) THEN
  4215. BEGIN
  4216. EXECUTE STATEMENT
  4217. 'CREATE GENERATOR GEN_JOB_LIST_ID';
  4218. END
  4219.  
  4220. /* Гарантируем таблицу */
  4221. SELECT result FROM IS_TABLE_EXISTS('JOB_LIST')
  4222. INTO :is_exist;
  4223.  
  4224. IF (is_exist = 0) THEN
  4225. BEGIN
  4226. EXECUTE STATEMENT
  4227. 'CREATE TABLE JOB_LIST (
  4228. ID_JOB_LIST INTEGER NOT NULL,
  4229. NAME VARCHAR(200) NOT NULL,
  4230. ID_OWNER INTEGER NOT NULL,
  4231. constraint PK_JOB_LIST primary key (ID_JOB_LIST))';
  4232. END
  4233. END ^
  4234. SET TERM ; ^
  4235. commit;
  4236. EXECUTE PROCEDURE TMP_JOB_LIST_CREATE;
  4237. commit;
  4238. DROP PROCEDURE TMP_JOB_LIST_CREATE;
  4239. commit;
  4240. /*---------------------------------------------------------------------------------------*/
  4241. /* 3.2 Создаем триггер для генерации ID */
  4242. /*---------------------------------------------------------------------------------------*/
  4243. SET TERM ^;
  4244. CREATE OR ALTER TRIGGER JOB_LIST_BI_GEN_ID
  4245. FOR JOB_LIST
  4246. ACTIVE BEFORE INSERT
  4247. AS
  4248. BEGIN
  4249. IF (NEW.ID_JOB_LIST IS NULL) THEN
  4250. NEW.ID_JOB_LIST = GEN_ID(GEN_JOB_LIST_ID, 1);
  4251. END^
  4252. SET TERM ; ^
  4253. commit;
  4254. /*---------------------------------------------------------------------------------------*/
  4255. /* 3.3 раздаем гранты на таблицу */
  4256. /*---------------------------------------------------------------------------------------*/
  4257. EXECUTE PROCEDURE GIVE_GRANTS_TO_ALL('TABLE','JOB_LIST','ALL');
  4258. commit;
  4259. /*---------------------------------------------------------------------------------------*/
  4260. /* 4.1 Создаем таблицу jobs_object, в ней будет: локальный id, тип объекта, его ид и ид задания */
  4261. /*---------------------------------------------------------------------------------------*/
  4262. SET TERM ^ ;
  4263. CREATE OR ALTER PROCEDURE TMP_JOBS_OBJECT_CREATE
  4264. AS
  4265. declare variable is_exist smallint;
  4266. BEGIN
  4267.  
  4268. /* Гарантируем генератор */
  4269. SELECT result FROM IS_GENERATOR_EXISTS('GEN_JOBS_OBJECT_ID')
  4270. INTO :is_exist;
  4271.  
  4272. IF (is_exist = 0) THEN
  4273. BEGIN
  4274. EXECUTE STATEMENT
  4275. 'CREATE GENERATOR GEN_JOBS_OBJECT_ID';
  4276. END
  4277.  
  4278. /* Гарантируем таблицу */
  4279. SELECT result FROM IS_TABLE_EXISTS('JOBS_OBJECT')
  4280. INTO :is_exist;
  4281.  
  4282. IF (is_exist = 0) THEN
  4283. BEGIN
  4284. EXECUTE STATEMENT
  4285. 'CREATE TABLE JOBS_OBJECT (
  4286. ID_JOBS_OBJECT INTEGER NOT NULL,
  4287. ID_JOB INTEGER NOT NULL,
  4288. ID_JOBS_OBJECT_TYPE INTEGER NOT NULL,
  4289. ID_OBJECT INTEGER NOT NULL,
  4290. constraint PK_JOBS_OBJECT primary key (ID_JOBS_OBJECT))';
  4291. END
  4292. END ^
  4293. SET TERM ; ^
  4294. commit;
  4295. EXECUTE PROCEDURE TMP_JOBS_OBJECT_CREATE;
  4296. commit;
  4297. DROP PROCEDURE TMP_JOBS_OBJECT_CREATE;
  4298. commit;
  4299. /*---------------------------------------------------------------------------------------*/
  4300. /* 4.2 Создаем триггер для генерации ID */
  4301. /*---------------------------------------------------------------------------------------*/
  4302. SET TERM ^;
  4303. CREATE OR ALTER TRIGGER JOBS_OBJECT_BI_GEN_ID
  4304. FOR JOBS_OBJECT
  4305. ACTIVE BEFORE INSERT
  4306. AS
  4307. BEGIN
  4308. IF (NEW.ID_JOBS_OBJECT IS NULL) THEN
  4309. NEW.ID_JOBS_OBJECT = GEN_ID(GEN_JOBS_OBJECT_ID, 1);
  4310. END^
  4311. SET TERM ; ^
  4312. commit;
  4313. /*---------------------------------------------------------------------------------------*/
  4314. /* 4.3 раздаем гранты на таблицу */
  4315. /*---------------------------------------------------------------------------------------*/
  4316. EXECUTE PROCEDURE GIVE_GRANTS_TO_ALL('TABLE','JOBS_OBJECT','ALL');
  4317. commit;
  4318. /*---------------------------------------------------------------------------------------*/
  4319. /* В очередной раз становимся лучше. теперь так: для запускающих задание объектов одна таблица
  4320. , различаем по типам - 1 - события, 2- задачи, дальше разберемся*/
  4321. /*---------------------------------------------------------------------------------------*/
  4322. SET TERM ^ ;
  4323. CREATE OR ALTER PROCEDURE TMP_EVENT_JOBS_CREATE
  4324. AS
  4325. declare variable is_exist smallint;
  4326. BEGIN
  4327.  
  4328. SELECT result FROM IS_TABLE_EXISTS('JOBBERS')
  4329. INTO :is_exist;
  4330.  
  4331. IF (is_exist = 0) THEN
  4332. BEGIN
  4333. EXECUTE STATEMENT
  4334. 'CREATE TABLE JOBBERS (
  4335. ID_JOB_LIST INTEGER NOT NULL,
  4336. ID_JOBBER INTEGER NOT NULL,
  4337. ID_JOBBER_TYPE INTEGER NOT NULL,
  4338. constraint PK_JOBBERS primary key (ID_JOB_LIST, ID_JOBBER, ID_JOBBER_TYPE))';
  4339. END
  4340. END ^
  4341. SET TERM ; ^
  4342. commit;
  4343. EXECUTE PROCEDURE TMP_EVENT_JOBS_CREATE;
  4344. commit;
  4345. DROP PROCEDURE TMP_EVENT_JOBS_CREATE;
  4346. commit;
  4347. /*---------------------------------------------------------------------------------------*/
  4348. /* раздаем гранты на таблицу */
  4349. /*---------------------------------------------------------------------------------------*/
  4350. EXECUTE PROCEDURE GIVE_GRANTS_TO_ALL('TABLE','JOBBERS','ALL');
  4351. commit;
  4352. /*---------------------------------------------------------------------------------------*/
  4353. /* добавляем признак "Выполненное задание" в события */
  4354. /*---------------------------------------------------------------------------------------*/
  4355. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('CALENDAR_PERIODS', 'ISEXECT', 'SMALLINT');
  4356.  
  4357. RESULT
  4358. =======
  4359. 1
  4360.  
  4361. commit;
  4362. /*---------------------------------------------------------------------------------------*/
  4363. /* сбрасываем этот признак для событий, которые уже наступили*/
  4364. /*---------------------------------------------------------------------------------------*/
  4365. UPDATE CALENDAR_PERIODS SET ISEXECT = 1 WHERE START_DATE < 'NOW';
  4366. commit;
  4367. /*---------------------------------------------------------------------------------------*/
  4368. /* stasy: Задания по событиям - конец*/
  4369. /*---------------------------------------------------------------------------------------*/
  4370. /*---------------------------------------------------------------------------------------*/
  4371. /* stasy: Цепочки задач - начало*/
  4372. /*---------------------------------------------------------------------------------------*/
  4373. /*---------------------------------------------------------------------------------------*/
  4374. /* добавляем поле для списков заданий в шаблоны задач */
  4375. /*---------------------------------------------------------------------------------------*/
  4376. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('TASK_TEMPLATES', 'ID_JOB_LIST', 'INTEGER');
  4377.  
  4378. RESULT
  4379. =======
  4380. 1
  4381.  
  4382. commit;
  4383. /*---------------------------------------------------------------------------------------*/
  4384. /* stasy: Цепочки задач - конец*/
  4385. /*---------------------------------------------------------------------------------------*/
  4386.  
  4387. /* Делаем процедуру, которая строит дерево инициаторов или контролеров типа документа в зависимости от параметра i_right_kind */
  4388. SET TERM ^ ;
  4389.  
  4390. CREATE OR ALTER PROCEDURE GETPERMREE_FOR_EMPLOYER_DOC (
  4391. i_id integer,
  4392. i_doctypeid integer,
  4393. i_right_kind integer)
  4394. returns (
  4395. o_id integer,
  4396. o_name varchar(200),
  4397. o_level integer)
  4398. as
  4399. declare variable l_k smallint;
  4400. declare variable l_empid integer;
  4401. declare variable l_pred_level integer;
  4402. begin
  4403. l_k = 0;
  4404. l_pred_level = 0;
  4405. for select O_ID,O_NAME,O_LEVEL
  4406. from GETPERMISSIONTREE_FOR_EMPLOYER (:i_id, 0)
  4407. into :O_ID, :o_name, :o_level
  4408. do
  4409. begin
  4410. l_k = 0;
  4411. for select p.id_employer
  4412. from permission p
  4413. join employer e on e.id = p.id_employer
  4414. where e.id_department=:o_id and p.id_boss=:i_id and p.enabled>0 and :l_k=0
  4415. into :L_EMPID
  4416. do
  4417. begin
  4418. if (exists(select grc.id_object
  4419. from grouprights_content grc
  4420. join GROUPRIGHTS_EMPLOYER gre on gre.id_groupright = grc.id_groupright
  4421. where gre.id_employer = :L_EMPID and
  4422. grc.right_kind=:i_right_kind and
  4423. grc.id_object=:i_doctypeid)) then
  4424. l_k=1;
  4425. end
  4426. if (l_k=1) then
  4427. begin
  4428. if (o_level - l_pred_level > 1) then
  4429. o_level = o_level - 1;
  4430. l_pred_level = o_level;
  4431. suspend;
  4432. end
  4433. end
  4434. end^
  4435.  
  4436. SET TERM ; ^
  4437. commit;
  4438.  
  4439. EXECUTE PROCEDURE GIVE_GRANTS_TO_ALL('PROCEDURE','GETPERMREE_FOR_EMPLOYER_DOC','EXECUTE');
  4440. commit;
  4441.  
  4442. /* Признак "Скрывать при поиске" для полей типа задачи */
  4443. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('META_FIELD', 'ISHIDEINSEARCH', 'SMALLINT');
  4444.  
  4445. RESULT
  4446. =======
  4447. 1
  4448.  
  4449. commit;
  4450.  
  4451. /* Шаблон справочника */
  4452. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('META_FIELD', 'DICTIONARY_TEMPLATE', 'VARCHAR(1000)');
  4453.  
  4454. RESULT
  4455. =======
  4456. 1
  4457.  
  4458. commit;
  4459.  
  4460. /* Флаг необходимости смены пароля */
  4461. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('EMPLOYER', 'NEEDPASSWORDCHANGE', 'SMALLINT');
  4462.  
  4463. RESULT
  4464. =======
  4465. 1
  4466.  
  4467. commit;
  4468.  
  4469. /* Elena - Добавила сброс флага NEEDPASSWORDCHANGE при смене пароля*/
  4470. SET TERM ^ ;
  4471.  
  4472. CREATE OR ALTER TRIGGER EMPLOYER_AU0 FOR EMPLOYER
  4473. ACTIVE AFTER UPDATE POSITION 0
  4474. as
  4475. declare variable bossid integer;
  4476. declare variable fbossid integer;
  4477. declare variable projid integer;
  4478. declare variable flag integer;
  4479. declare variable l_empid integer;
  4480. declare variable l_isdeleted integer;
  4481. declare variable l_enabled smallint;
  4482. begin
  4483. if (new.isdeleted = 1 and old.isdeleted = 0) then
  4484. begin
  4485. /* for select id_boss
  4486. from permission
  4487. where id_employer = new.id and
  4488. enabled >0
  4489. into :l_empid
  4490. do
  4491. begin
  4492. select isdeleted from employer where id = :l_empid
  4493. into :l_isdeleted;
  4494. if (l_isdeleted=0) then
  4495. execute procedure set_permission_dep (l_empid, new.id);
  4496. end */
  4497.  
  4498. update permission
  4499. set enabled=0
  4500. where id_boss=new.id;
  4501.  
  4502. /* update permission
  4503. set enabled=0
  4504. where id_employer=new.id; */
  4505.  
  4506. /* Удаляем из всех пользовательских деревьев */
  4507. delete from ud_employer where id_employer=new.id;
  4508. end
  4509.  
  4510. if (new.isdeleted = 0 and old.isdeleted=1) then
  4511. execute procedure convertpermissions (new.id, new.isboss);
  4512.  
  4513. if (new.id_department != old.id_department) then
  4514. begin
  4515. for select distinct t.id_project
  4516. from grouptask gt
  4517. left join task t on (gt.id_task=t.id)
  4518. where gt.id_employer = old.id and gt.is_respperson=1
  4519. into :projid
  4520. do
  4521. begin
  4522. flag = null;
  4523. select count(id_project) from PROJECT_DEP
  4524. where id_Project = :projid and ID_Department = new.id_department
  4525. into :flag; /*проверяем не привязан ли уже этот проект к новому подразделению*/
  4526.  
  4527. if ((flag is null) or (flag = 0)) then /*если нет, то привязываем*/
  4528. insert into PROJECT_DEP (ID_Project, ID_Department)
  4529. values (:projid,new.id_department);
  4530.  
  4531. flag = null;
  4532. /* old begin */
  4533. /* select count (t.id) --проверяем остались ли еще задачи для этого проекта в старом подразделении
  4534. from task t
  4535. join employer e on t.id_employer = e.id
  4536. where t.id_project =:projid and
  4537. t.ID_employer != old.id and
  4538. e.id_department = old.id_department
  4539. into :flag;
  4540. */ /* old end */
  4541.  
  4542. /* new begin */
  4543. select count (t.id) /*проверяем остались ли еще задачи для этого проекта в старом подразделении*/
  4544. from task t
  4545. join grouptask gt on (t.id = gt.id_task and gt.is_worker = 1)
  4546. join employer e on gt.id_employer = e.id
  4547. where t.id_project =:projid and
  4548. gt.ID_employer != old.id and
  4549. e.id_department = old.id_department
  4550. into :flag;
  4551. /* new end */
  4552.  
  4553. if ((flag is null) or (flag = 0)) then /*если нет, то удаляем привязку этого проекта к подразделению*/
  4554. delete from PROJECT_DEP where
  4555. id_project = :projid and
  4556. id_department = old.id_department;
  4557. end
  4558.  
  4559. update permission
  4560. set enabled = 0
  4561. where id_boss = new.id and
  4562. is_manual=0;
  4563. execute procedure convertpermissions (new.id, new.isboss);
  4564. /*Обновляем deppermission для боссов данного пользователя*/
  4565. for select id_boss,enabled
  4566. from permission
  4567. where id_employer = new.id and
  4568. enabled <> 0
  4569. into :l_empid,:l_enabled
  4570. do
  4571. begin
  4572. select isdeleted from employer where id = :l_empid
  4573. into :l_isdeleted;
  4574. if (l_isdeleted = 0) then
  4575. begin
  4576. /* Проверяем имеет ли начальник права на отдел в который перевели чела
  4577. * и если нет, то удаляем права начальника на чела
  4578. */
  4579. if (not (exists(select d.enabled
  4580. from deppermission d
  4581. where d.id_employer=:l_empid and
  4582. d.id_department = new.id_department and
  4583. d.enabled = :l_enabled))) then
  4584. delete from permission p
  4585. where p.id_boss = :l_empid and
  4586. p.id_employer = new.id;
  4587. else
  4588. execute procedure set_permission_dep (l_empid, new.id);
  4589.  
  4590.  
  4591. /*Проверяем старое подразделение и удаляем его из deppermission, если там
  4592. больше нет пользователей, на которых босс имеет права*/
  4593. if (not exists(select p.id_boss
  4594. from permission p
  4595. join employer e on e.id = p.id_employer
  4596. where e.id_department = old.id_department and
  4597. p.id_boss = :l_empid and
  4598. enabled = :l_enabled)) then
  4599. begin
  4600. delete from deppermission
  4601. where id_department = old.id_department and
  4602. id_employer = :l_empid and
  4603. enabled = :l_enabled;
  4604. end
  4605. end
  4606. end
  4607.  
  4608. end
  4609.  
  4610. if (old.isboss <> new.isboss) then /*смена статуса сотрудника, переделываем полномочия*/
  4611. execute procedure convertpermissions (new.id, new.isboss);
  4612.  
  4613. if (old.pass <> new.pass and old.needpasswordchange = new.needpasswordchange) then
  4614. update employer
  4615. set needpasswordchange = 0
  4616. where id = new.id;
  4617.  
  4618. if (old.name<>new.name or
  4619. old.isboss<>new.isboss or
  4620. old.login<>new.login or
  4621. old.pass<>new.pass or
  4622. old.isdeleted<>new.isdeleted or
  4623. old.email<>new.email or
  4624. old.cphone<>new.cphone or
  4625. old.workphone<>new.workphone or
  4626. old.birthdate<>new.birthdate or
  4627. old.postaddress<>new.postaddress or
  4628. old.homephone<>new.homephone or
  4629. old.cphone2<>new.cphone2 or
  4630. old.commnt<>new.commnt or
  4631. old.manpost<>new.manpost or
  4632. old.fastlogin<>new.fastlogin or
  4633. old.awayto<>new.awayto
  4634. ) then
  4635. update employer
  4636. set name = new.name,
  4637. isboss = new.isboss,
  4638. login = new.login,
  4639. pass = new.pass,
  4640. isdeleted = new.isdeleted,
  4641. email = new.email,
  4642. cphone = new.cphone,
  4643. workphone = new.workphone,
  4644. birthdate = new.birthdate,
  4645. postaddress = new.postaddress,
  4646. homephone = new.homephone,
  4647. cphone2 = new.cphone2,
  4648. commnt = new.commnt,
  4649. manpost = new.manpost,
  4650. fastlogin = new.fastlogin,
  4651. awayto=new.awayto
  4652. where parentid = new.id and
  4653. isdeleted = 0;
  4654. end^
  4655.  
  4656. SET TERM ; ^
  4657. commit;
  4658.  
  4659. /*-------------------------------------------------------------------------------------------------------------------------------*/
  4660. /* пункт меню "Интеграция с LDAP" */
  4661. /*-------------------------------------------------------------------------------------------------------------------------------*/
  4662.  
  4663. EXECUTE PROCEDURE ADDMENUITEMBYTAG(869, 'L_MENU_LDAP', 'http://ldapsync_host:ldapsync_port', 'L_MENU_ADMINISTRATION', 21, 1, 6, NULL);
  4664. commit;
  4665.  
  4666. /* Elena - Добавила выходной параметр id_tasktype*/
  4667. SET TERM ^ ;
  4668.  
  4669. CREATE OR ALTER PROCEDURE GETTASKINFO4SF (
  4670. idemployer integer,
  4671. idtask integer)
  4672. returns (
  4673. taskid integer,
  4674. tasknumber varchar(200),
  4675. priority integer,
  4676. taskname varchar(2000),
  4677. startdate date,
  4678. enddate date,
  4679. author varchar(10000),
  4680. controller varchar(10000),
  4681. responsible varchar(10000),
  4682. worker varchar(10000),
  4683. projectname varchar(10000),
  4684. tasktype varchar(10000),
  4685. taskstate char(4),
  4686. marker integer,
  4687. id_tasktype integer)
  4688. as
  4689. declare variable is_author smallint;
  4690. declare variable is_controller smallint;
  4691. declare variable is_responsible smallint;
  4692. declare variable is_worker smallint;
  4693. declare variable emp_name varchar(2000);
  4694. declare variable act_cnt integer;
  4695. declare variable istasknew smallint;
  4696. declare variable isactnew smallint;
  4697. declare variable isreport smallint;
  4698. declare variable isreject smallint;
  4699. declare variable i integer;
  4700. declare variable sql varchar(1000);
  4701. BEGIN
  4702. SQL = '';
  4703. if (idtask<>-1) then
  4704. begin
  4705. SQL = ' and t.ID = ' || :idtask;
  4706. end
  4707. for EXECUTE STATEMENT 'select
  4708. t.ID,
  4709. lower(t.NUMERATOR),
  4710. t.PRIORITY,
  4711. lower(t.NAME),
  4712. t.STARTDATE,
  4713. t.ENDDATE,
  4714. lower(p.NAME),
  4715. lower(md.NAME),
  4716. md.id,
  4717. ta.MARKER_COLOR,
  4718. t.action_count,
  4719. (1 - gt.IS_VIEWED_TASK),
  4720. (1-(case ta.IS_VIEW_NEW_ACTIONS when (ta.IS_VIEW_NEW_ACTIONS) then ta.IS_VIEW_NEW_ACTIONS else 0 end)),
  4721. t.ISREPORTED,
  4722. t.ISREJECTED
  4723. from
  4724. TASK t
  4725. join GROUPTASK gt on
  4726. t.ID = gt.ID_TASK
  4727. join PROJECT p on
  4728. p.id = t.ID_PROJECT
  4729. join META_DICTIONARY md on
  4730. md.ID = t.ID_META_DICTIONARY
  4731. left join TASK_ATTRIBUTES ta on
  4732. ta.ID_TASK = gt.ID_TASK and ta.id_employer=gt.id_original
  4733. where
  4734. gt.id_original = ' || :idemployer || ' and gt.task_state=0' || :SQL
  4735. into
  4736. :TASKID,
  4737. :TASKNUMBER,
  4738. :PRIORITY,
  4739. :TASKNAME,
  4740. :STARTDATE,
  4741. :ENDDATE,
  4742. :PROJECTNAME,
  4743. :TASKTYPE,
  4744. :ID_TASKTYPE,
  4745. :MARKER,
  4746. :ACT_CNT,
  4747. :istasknew,
  4748. :isactnew,
  4749. :isreport,
  4750. :isreject
  4751. do
  4752. begin
  4753. Author = '';
  4754. Controller = '';
  4755. Responsible = '';
  4756. Worker = '';
  4757. for
  4758. select
  4759. gt.IS_AUTHOR,
  4760. gt.IS_CONTROLER,
  4761. gt.IS_RESPPERSON,
  4762. gt.IS_WORKER,
  4763. e.NAME
  4764. from
  4765. GROUPTASK gt
  4766. join EMPLOYER e on
  4767. e.ID = gt.ID_EMPLOYER
  4768. where
  4769. gt.ID_TASK = :TASKID
  4770. into
  4771. :is_author,
  4772. :is_controller,
  4773. :is_responsible,
  4774. :is_worker,
  4775. :emp_name
  4776. do
  4777. begin
  4778. if (is_author = 1) then
  4779. begin
  4780. if (Author <> '') then Author = Author || ',';
  4781. Author = Author || emp_name;
  4782. end
  4783.  
  4784. if (is_controller = 1) then
  4785. begin
  4786. if (Controller <> '') then Controller = Controller || ',';
  4787. Controller = Controller || emp_name;
  4788. end
  4789.  
  4790. if (is_responsible = 1) then
  4791. begin
  4792. if (Responsible <> '') then Responsible = Responsible || ',';
  4793. Responsible = Responsible || emp_name;
  4794. end
  4795.  
  4796. if (is_worker = 1) then
  4797. begin
  4798. if (Worker <> '') then Worker = Worker || ',';
  4799. Worker = Worker || emp_name;
  4800. end
  4801. end
  4802.  
  4803. if ( ( (ACT_CNT=0)or(ACT_CNT is null) ) ) then isactnew = 0;
  4804. if (isreject is null) then isreject = 0;
  4805. taskstate = istasknew || isactnew || isreport || isreject;
  4806.  
  4807. SUSPEND;
  4808. end
  4809. END^
  4810.  
  4811. SET TERM ; ^
  4812. commit;
  4813.  
  4814. /*-------------------------------------------------------------------------------------------------------------------------------*/
  4815. /*stasy: shablon otobrajenia imeni documenta begining*/
  4816. /*-------------------------------------------------------------------------------------------------------------------------------*/
  4817. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('DOCTYPES', 'DISPLAY_NAME', 'VARCHAR(1000)');
  4818.  
  4819. RESULT
  4820. =======
  4821. 1
  4822.  
  4823. commit;
  4824. /*-------------------------------------------------------------------------------------------------------------------------------*/
  4825. /*shablon otobrajenia imeni documenta end*/
  4826. /*-------------------------------------------------------------------------------------------------------------------------------*/
  4827. /*tip resolucii - begin*/
  4828. /*isnachalno nepravilno bilo, chishu*/
  4829. /*-------------------------------------------------------------------------------------------------------------------------------*/
  4830. delete from doccards where FIELDID = 'RESOLUTION_TYPE' and FIELDTYPE = 104;
  4831. commit;
  4832. /*-------------------------------------------------------------------------------------------------------------------------------*/
  4833. SET TERM ^ ;
  4834. CREATE OR ALTER PROCEDURE DROD_FIELD_IF_EXIST
  4835. (
  4836. table_name varchar(50),
  4837. field_name varchar(50)
  4838. )
  4839. RETURNS
  4840. (
  4841. result SMALLINT
  4842. )
  4843. AS
  4844. DECLARE VARIABLE is_exist SMALLINT;
  4845. BEGIN
  4846. result = 0;
  4847.  
  4848. SELECT result FROM IS_FIELD_EXISTS(:table_name, :field_name)
  4849. INTO :is_exist;
  4850.  
  4851. IF (is_exist > 0) THEN
  4852. BEGIN
  4853. table_name = UPPER(table_name);
  4854. field_name = UPPER(field_name);
  4855.  
  4856. EXECUTE STATEMENT
  4857. 'ALTER TABLE ' || table_name || ' DROP ' || field_name ;
  4858.  
  4859. result = 1;
  4860. END
  4861.  
  4862. SUSPEND;
  4863. END^
  4864. SET TERM ; ^
  4865. COMMIT;
  4866. /*-------------------------------------------------------------------------------------------------------------------------------*/
  4867. EXECUTE PROCEDURE DROD_FIELD_IF_EXIST('DOCCARDS', 'RESOLUTION_TYPE');
  4868.  
  4869. RESULT
  4870. =======
  4871. 0
  4872.  
  4873. commit;
  4874. /*-------------------------------------------------------------------------------------------------------------------------------*/
  4875. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('DOCTYPES', 'RESOLUTION_TYPE', 'INTEGER');
  4876.  
  4877. RESULT
  4878. =======
  4879. 1
  4880.  
  4881. commit;
  4882. /*tip resolucii - end*/
  4883. /*-------------------------------------------------------------------------------------------------------------------------------*/
  4884.  
  4885. EXECUTE PROCEDURE ADD_INDEX_IF_DOES_NOT_EXIST('IDX_META_FIELD1','META_FIELD','NAME, ISDELETED');
  4886.  
  4887. RESULT
  4888. =======
  4889. 1
  4890.  
  4891. commit;
  4892.  
  4893. EXECUTE PROCEDURE ADD_INDEX_IF_DOES_NOT_EXIST('DOCTYPES_IDX1', 'DOCTYPES', 'ISDELETED');
  4894.  
  4895. RESULT
  4896. =======
  4897. 0
  4898.  
  4899. commit;
  4900.  
  4901. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  4902. /*01.03.2011, Alisa.Kot, task 270434
  4903. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  4904. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  4905. SET TERM ^ ;
  4906. CREATE OR ALTER PROCEDURE GETTASKEXECDOCBUTOUTDATE_1 (
  4907. I_FROM_DATE Timestamp,
  4908. I_TO_DATE Timestamp,
  4909. I_ID_DEPARTMENT Integer )
  4910. RETURNS (
  4911. O_TASKID Integer,
  4912. O_PROJID Integer,
  4913. O_DOC_EXEC_ID Integer )
  4914. AS
  4915. begin
  4916. for select t.id, t.id_project
  4917. from task t
  4918. where t.state = 1 and
  4919. t.isdeleted = 0 and
  4920. t.tsreport > t.enddate and
  4921. t.id_department = :i_id_department and
  4922. t.enddate between :i_from_date and :i_to_date and
  4923. t.tsreport between :i_from_date and :i_to_date
  4924. into :o_taskid, :O_PROJID
  4925. do
  4926. suspend;
  4927.  
  4928. end^
  4929. SET TERM ; ^
  4930. commit;
  4931.  
  4932. SET TERM ^ ;
  4933. CREATE OR ALTER PROCEDURE GETTASKEXECDOCBUTOUTDATE (
  4934. I_ID_EMPLOYER Integer,
  4935. I_ID_DEPARTMENT Integer,
  4936. I_ONLY_THIS_DEP Smallint,
  4937. I_FROM_DATE Timestamp,
  4938. I_TO_DATE Timestamp )
  4939. RETURNS (
  4940. O_TASK_NAME Varchar(2000),
  4941. O_AUTHOR Varchar(2000),
  4942. O_ADATE Timestamp,
  4943. O_TASKID Integer,
  4944. O_AUTHORID Integer,
  4945. O_TASKENDDATE Timestamp,
  4946. O_STATE Smallint,
  4947. O_ACT_EMPID Integer,
  4948. O_TASKSTARTDATE Timestamp,
  4949. O_EMPLOYERID Integer,
  4950. O_EMPLOYERNAME Varchar(2000),
  4951. O_ISBOSS Smallint,
  4952. O_PROJID Integer,
  4953. O_PROJECT_NAME Varchar(200),
  4954. O_DIFFTIME Timestamp,
  4955. O_NUMERATOR Varchar(1000),
  4956. O_TSREPORT Timestamp )
  4957. AS
  4958. DECLARE VARIABLE L_DEPID INTEGER;
  4959. DECLARE VARIABLE L_LAST_ACTIONID INTEGER;
  4960. DECLARE VARIABLE L_LAST_ACTIONTIME TIMESTAMP;
  4961. DECLARE VARIABLE L_REPORTDATE TIMESTAMP;
  4962. DECLARE VARIABLE L_LEFTDATE TIMESTAMP;
  4963. DECLARE VARIABLE L_RIGHTDATE TIMESTAMP;
  4964. DECLARE VARIABLE L_RESULT SMALLINT;
  4965. DECLARE VARIABLE L_ROOT_DEP INTEGER;
  4966. DECLARE VARIABLE L_HASCHILDS INTEGER;
  4967. DECLARE VARIABLE L_TASK_DOC_EXEC_ID INTEGER;
  4968. DECLARE VARIABLE L_DOCID INTEGER;
  4969. DECLARE VARIABLE L_DOC_TYPE_ID INTEGER;
  4970. DECLARE VARIABLE L_DOC_STATE SMALLINT;
  4971. DECLARE VARIABLE L_IS_WHITH_REPORT SMALLINT;
  4972. DECLARE VARIABLE L_ISREPORTED SMALLINT;
  4973. begin
  4974.  
  4975. if (:i_id_department is not null) then
  4976. begin
  4977. l_root_dep = :i_id_department;
  4978. end
  4979. else
  4980. select id_department from employer where id=:i_id_employer
  4981. into :l_root_dep;
  4982. if (:i_only_this_dep = 0) then
  4983. begin
  4984. select haschilds from department where id = :l_root_dep
  4985. into :l_haschilds;
  4986. if (:l_haschilds = 0) then
  4987. i_only_this_dep = 1;
  4988. end
  4989. for select g.o_taskid, g.o_projid
  4990. from gettaskexecdocbutoutdate_1(:i_from_date, :i_to_date, :l_root_dep) g
  4991. into :o_taskid, :o_projid
  4992. do
  4993. begin
  4994. execute procedure checkrightsfortask(:i_id_employer, :o_taskid)
  4995. returning_values :l_result;
  4996. if(:l_result = 1) then
  4997. begin
  4998. select t.name, t.startdate, t.enddate, t.la_id, t.iswithreport, t.isreported, t.tsreport, t.numerator
  4999. from task t
  5000. where t.id = :o_taskid
  5001. into :o_task_name, :o_taskstartdate, :o_taskenddate, :l_last_actionid, :l_is_whith_report, :l_isreported, :l_reportdate, :O_NUMERATOR;
  5002.  
  5003. select first 1 a.adate
  5004. from actions a
  5005. where a.id=:l_last_actionid
  5006. into :l_last_actiontime;
  5007.  
  5008. select first 1 gt.id_employer
  5009. from grouptask gt
  5010. where gt.id_task=:o_taskid and gt.is_author=1
  5011. into :o_authorid;
  5012.  
  5013. select first 1 gt.id_employer
  5014. from grouptask gt
  5015. where gt.id_task=:o_taskid and gt.is_respperson=1
  5016. into :o_employerid;
  5017.  
  5018. select name from employer where id = :o_authorid
  5019. into :o_author;
  5020.  
  5021. select p.name from project p
  5022. where p.id = :o_projid
  5023. into :O_PROJECT_NAME;
  5024.  
  5025. select name from employer where id = :o_employerid
  5026. into :o_employername;
  5027. /* if (l_is_whith_report=1) then
  5028. begin
  5029. if (l_isreported=1) then
  5030. begin
  5031. l_leftdate=:l_reportdate;
  5032. l_rightdate=:o_taskenddate;
  5033. O_DIFFTIME = cast((cast(:l_leftdate as timestamp)-cast(:l_rightdate as timestamp))*100 as integer)/100;
  5034. end
  5035. else
  5036. begin
  5037. O_DIFFTIME = cast((cast(:l_last_actiontime as timestamp)-cast(:o_taskenddate as timestamp))*100 as integer)/100;
  5038. end
  5039. end
  5040. else
  5041. begin
  5042. O_DIFFTIME = cast((cast(:l_last_actiontime as timestamp)-cast(:o_taskenddate as timestamp))*100 as integer)/100;
  5043. end
  5044. */
  5045. --O_DIFFTIME = :l_reportdate - :o_taskenddate;
  5046. O_TSREPORT = :l_reportdate;
  5047. suspend;
  5048. end
  5049. end
  5050. if (:i_only_this_dep = 0) then
  5051. begin
  5052. for select id_department
  5053. from deppermission
  5054. where id_employer=:i_id_employer and enabled > 0
  5055. into :l_depid
  5056. do
  5057. begin
  5058. select o_result from is_sub_dep(:l_depid, :l_root_dep) into :l_result;
  5059. if (:l_result = 1) then
  5060. begin
  5061. for select g.o_taskid, g.o_projid
  5062. from gettaskexecdocbutoutdate_1(:i_from_date, :i_to_date, :l_depid) g
  5063. into :o_taskid, :o_projid
  5064. do
  5065. begin
  5066. execute procedure checkrightsfortask(:i_id_employer, :o_taskid)
  5067. returning_values :l_result;
  5068. if(:l_result = 1) then
  5069. begin
  5070. select t.name, t.startdate, t.enddate, t.la_id, t.iswithreport, t.isreported, t.tsreport, t.numerator
  5071. from task t
  5072. where t.id = :o_taskid
  5073. into :o_task_name, :o_taskstartdate, :o_taskenddate, :l_last_actionid, :l_is_whith_report, :l_isreported, :l_reportdate, :O_NUMERATOR;
  5074.  
  5075. select first 1 a.adate
  5076. from actions a
  5077. where a.id=:l_last_actionid
  5078. into :l_last_actiontime;
  5079.  
  5080. select first 1 gt.id_employer
  5081. from grouptask gt
  5082. where gt.id_task=:o_taskid and gt.is_author=1
  5083. into :o_authorid;
  5084.  
  5085. select first 1 gt.id_employer
  5086. from grouptask gt
  5087. where gt.id_task=:o_taskid and gt.is_respperson=1
  5088. into :o_employerid;
  5089.  
  5090. select name from employer where id = :o_authorid
  5091. into :o_author;
  5092.  
  5093. select p.name from project p
  5094. where p.id = :o_projid
  5095. into :O_PROJECT_NAME;
  5096.  
  5097. select name from employer where id = :o_employerid
  5098. into :o_employername;
  5099. --O_DIFFTIME = :l_reportdate - :o_taskenddate;
  5100. O_TSREPORT = :l_reportdate;
  5101. suspend;
  5102. end
  5103. end
  5104. end
  5105. end
  5106. end
  5107. end^
  5108. SET TERM ; ^
  5109. commit;
  5110.  
  5111. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  5112. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  5113. SET TERM ^ ;
  5114. CREATE OR ALTER PROCEDURE GETOUTDATED_1 (
  5115. I_ID_EMPLOYER Integer,
  5116. I_IS_BOSS Smallint,
  5117. I_ID_DEPARTMENT Smallint )
  5118. RETURNS (
  5119. O_TASKID Integer,
  5120. O_EMPLOYERID Integer,
  5121. O_DEPID Integer )
  5122. AS
  5123. DECLARE VARIABLE L_IS_BOSS SMALLINT;
  5124. DECLARE VARIABLE L_ISSECRET SMALLINT;
  5125. begin
  5126. for
  5127. select t.id,t.issecret
  5128. from task t
  5129. where
  5130. t.isdeleted =0 and
  5131. t.id_department = :i_id_department and
  5132. (select o_result from checkrightsfortask (:I_ID_EMPLOYER, t.id)) = 1 and
  5133. t.enddate < 'NOW' and
  5134. t.state = 0
  5135. into :O_TASKID,:l_issecret
  5136. do
  5137. begin
  5138. if (:l_issecret=0 or (:l_issecret=1 and
  5139. exists (select gt.id_task
  5140. from grouptask gt
  5141. where gt.id_task=:o_taskid and
  5142. gt.id_original=:i_id_employer) ) ) then
  5143. begin
  5144. for select gt.id_employer
  5145. from grouptask gt
  5146. where gt.id_task = :O_TASKID and
  5147. (gt.is_respperson=1 or gt.is_worker=1)
  5148. into :O_EMPLOYERID
  5149. do
  5150. begin
  5151. select id_department,isboss from employer
  5152. where id = :O_EMPLOYERID
  5153. into :O_DEPID,:l_is_boss;
  5154. if ((:I_IS_BOSS=1 and :l_is_boss=1) or :I_IS_BOSS=0) then
  5155. suspend;
  5156. end
  5157. end
  5158. end
  5159. end^
  5160. SET TERM ; ^
  5161. commit;
  5162.  
  5163. SET TERM ^ ;
  5164. CREATE OR ALTER PROCEDURE GETOUTDATED (
  5165. I_ID_EMPLOYER Integer,
  5166. I_DEPID Integer,
  5167. I_ONLY_BOSS Smallint,
  5168. I_ONLY_THIS_DEP Smallint )
  5169. RETURNS (
  5170. NAME Varchar(2000),
  5171. TASK_NAME Varchar(2000),
  5172. AUTHOR Varchar(2000),
  5173. CURR_ACTION Blob sub_type 1,
  5174. ADATE Timestamp,
  5175. TASKID Integer,
  5176. AUTHORID Integer,
  5177. TASKENDDATE Timestamp,
  5178. STATE Smallint,
  5179. ACT_EMPID Integer,
  5180. TASKSTARTDATE Timestamp,
  5181. EMPLOYERID Integer,
  5182. EMPLOYERNAME Varchar(2000),
  5183. ISBOSS Smallint,
  5184. O_PROJECT_ID Integer,
  5185. O_PROJECT_NAME Varchar(200),
  5186. O_DIFFTIME Integer,
  5187. O_NUMERATOR Varchar(1000) )
  5188. AS
  5189. declare variable L_TASKID integer;
  5190. declare variable L_STARTDATE timestamp;
  5191. declare variable L_DEPID integer;
  5192. declare variable L_AUTHORNAME varchar(2000);
  5193. declare variable L_RESULT smallint;
  5194. begin
  5195. for select
  5196. distinct g1.o_taskid
  5197. from getpermissiontree (:I_ID_EMPLOYER, :I_DEPID) gpt,
  5198. getoutdated_1(:I_ID_EMPLOYER,:i_only_boss,:i_depid) g1
  5199. where gpt.o_id = g1.o_depid
  5200. into :TASKID
  5201. do
  5202. begin
  5203. select NAME,
  5204. TASK_NAME,
  5205. AUTHOR,
  5206. CURR_ACTION,
  5207. ADATE,
  5208. AUTHORID,
  5209. TASKENDDATE,
  5210. STATE,
  5211. ACT_EMPID,
  5212. TASKSTARTDATE,
  5213. EMPLOYERID,
  5214. EMPLOYERNAME,
  5215. ISBOSS,
  5216. O_PROJECT_ID,
  5217. O_PROJECT_NAME,
  5218. O_DIFFTIME,
  5219. O_NUMERATOR
  5220. from getoutdated_3(:TASKID)
  5221. into :NAME,
  5222. :TASK_NAME,
  5223. :AUTHOR,
  5224. :CURR_ACTION,
  5225. :ADATE,
  5226. :AUTHORID,
  5227. :TASKENDDATE,
  5228. :STATE,
  5229. :ACT_EMPID,
  5230. :TASKSTARTDATE,
  5231. :EMPLOYERID,
  5232. :EMPLOYERNAME,
  5233. :ISBOSS,
  5234. :O_PROJECT_ID,
  5235. :O_PROJECT_NAME,
  5236. :O_DIFFTIME,
  5237. :O_NUMERATOR;
  5238. suspend;
  5239. end
  5240. if (:i_only_this_dep = 0) then
  5241. begin
  5242. for select id_department
  5243. from deppermission
  5244. where id_employer=:i_id_employer and enabled > 0
  5245. into :l_depid
  5246. do
  5247. begin
  5248. select o_result from is_sub_dep(:l_depid, :i_depid) into :l_result;
  5249. if (:l_result = 1) then
  5250. begin
  5251. for select
  5252. distinct g1.o_taskid
  5253. from getpermissiontree (:I_ID_EMPLOYER, :L_DEPID) gpt,
  5254. getoutdated_1(:I_ID_EMPLOYER,:i_only_boss,:l_depid) g1
  5255. where gpt.o_id = g1.o_depid
  5256. into :TASKID
  5257. do
  5258. begin
  5259. select NAME,
  5260. TASK_NAME,
  5261. AUTHOR,
  5262. CURR_ACTION,
  5263. ADATE,
  5264. AUTHORID,
  5265. TASKENDDATE,
  5266. STATE,
  5267. ACT_EMPID,
  5268. TASKSTARTDATE,
  5269. EMPLOYERID,
  5270. EMPLOYERNAME,
  5271. ISBOSS,
  5272. O_PROJECT_ID,
  5273. O_PROJECT_NAME,
  5274. O_DIFFTIME,
  5275. O_NUMERATOR
  5276. from getoutdated_3(:TASKID)
  5277. into :NAME,
  5278. :TASK_NAME,
  5279. :AUTHOR,
  5280. :CURR_ACTION,
  5281. :ADATE,
  5282. :AUTHORID,
  5283. :TASKENDDATE,
  5284. :STATE,
  5285. :ACT_EMPID,
  5286. :TASKSTARTDATE,
  5287. :EMPLOYERID,
  5288. :EMPLOYERNAME,
  5289. :ISBOSS,
  5290. :O_PROJECT_ID,
  5291. :O_PROJECT_NAME,
  5292. :O_DIFFTIME,
  5293. :O_NUMERATOR;
  5294. suspend;
  5295. end
  5296. end
  5297. end
  5298. end
  5299. end^
  5300. SET TERM ; ^
  5301. commit;
  5302. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  5303. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  5304. SET TERM ^ ;
  5305. CREATE OR ALTER PROCEDURE REPORT1 (
  5306. I_ID_EMPLOYER Integer,
  5307. I_DEPID Integer,
  5308. STARTDATE Timestamp,
  5309. ENDDATE Timestamp,
  5310. I_ONLY_THIS_DEP Smallint )
  5311. RETURNS (
  5312. NAME Varchar(2000),
  5313. TASK_NAME Varchar(2000),
  5314. CURR_ACTION Blob sub_type 1,
  5315. ADATE Timestamp,
  5316. TASKID Integer,
  5317. ISSTARTED Smallint,
  5318. PROJNAME Varchar(200),
  5319. DEPPATH Varchar(2000),
  5320. TASKENDDATE Timestamp,
  5321. STATE Smallint,
  5322. ISREJECTED Smallint,
  5323. PROJ_ID Integer,
  5324. ACT_EMPID Integer,
  5325. ACT_FIRST Integer,
  5326. TASKSTARTDATE Timestamp,
  5327. ISBOSS Smallint,
  5328. ISTRASHPROJECT Smallint )
  5329. AS
  5330. declare variable L_STARTDATE timestamp;
  5331. declare variable L_DEPID integer;
  5332. declare variable L_AUTHORNAME varchar(2000);
  5333. declare variable L_RESULT Smallint;
  5334. begin
  5335. if (I_DEPID <> 0) then
  5336. for select rf.name,
  5337. rf.TASK_NAME,
  5338. rf.taskstartdate,
  5339. rf.TASKID,
  5340. rf.isstarted,
  5341. rf.ProjName,
  5342. rf.deppath,
  5343. rf.taskenddate,
  5344. rf.STATE,
  5345. rf.isrejected,
  5346. rf.PROJ_ID,
  5347. rf.isboss,
  5348. rf.istrashproject,
  5349. rf.curr_action,
  5350. rf.adate,
  5351. rf.act_empid,
  5352. rf.act_first
  5353. from getpermissiontree (:I_ID_EMPLOYER, :I_DEPID) gpt,
  5354. report1_fast(:i_id_employer,:startdate,:enddate) rf
  5355. where rf.depid = gpt.o_id
  5356. into :name,
  5357. :TASK_NAME,
  5358. :taskstartdate,
  5359. :TASKID,
  5360. :isstarted,
  5361. :ProjName,
  5362. :deppath,
  5363. :taskenddate,
  5364. :STATE,
  5365. :isrejected,
  5366. :PROJ_ID,
  5367. :isboss,
  5368. :istrashproject,
  5369. :curr_action,
  5370. :adate,
  5371. :act_empid,
  5372. :act_first
  5373. do
  5374. suspend;
  5375. else
  5376. for select rf.name,
  5377. rf.TASK_NAME,
  5378. rf.taskstartdate,
  5379. rf.TASKID,
  5380. rf.isstarted,
  5381. rf.ProjName,
  5382. rf.deppath,
  5383. rf.taskenddate,
  5384. rf.STATE,
  5385. rf.isrejected,
  5386. rf.PROJ_ID,
  5387. rf.isboss,
  5388. rf.istrashproject,
  5389. rf.curr_action,
  5390. rf.adate,
  5391. rf.act_empid,
  5392. rf.act_first
  5393. from getpermissiontree_for_employer (:I_ID_EMPLOYER,0) gpt,
  5394. report1_fast(:i_id_employer,:startdate,:enddate) rf
  5395. where rf.depid = gpt.o_id
  5396. into :name,
  5397. :TASK_NAME,
  5398. :taskstartdate,
  5399. :TASKID,
  5400. :isstarted,
  5401. :ProjName,
  5402. :deppath,
  5403. :taskenddate,
  5404. :STATE,
  5405. :isrejected,
  5406. :PROJ_ID,
  5407. :isboss,
  5408. :istrashproject,
  5409. :curr_action,
  5410. :adate,
  5411. :act_empid,
  5412. :act_first
  5413. do
  5414. suspend;
  5415.  
  5416. if (:i_only_this_dep = 0) then
  5417. begin
  5418. for select id_department
  5419. from deppermission
  5420. where id_employer=:i_id_employer and enabled > 0
  5421. into :l_depid
  5422. do
  5423. begin
  5424. select o_result from is_sub_dep(:l_depid, :i_depid) into :l_result;
  5425. if (:l_result = 1) then
  5426. begin
  5427. for select t.name,
  5428. t.id,
  5429. t.startdate,
  5430. t.enddate,
  5431. t.state,
  5432. t.id_project,
  5433. t.isrejected,
  5434. t.isstarted,
  5435. a.name,
  5436. a.isfirst,
  5437. a.adate,
  5438. a.id_employer,
  5439. e.name,
  5440. e.isboss
  5441. from actions a
  5442. join task t on t.la_id = a.id
  5443. left join employer e on a.id_employer=e.id
  5444. where a.adate between :startdate and :enddate and
  5445. t.isdeleted = 0 and
  5446. e.id_department= :l_depid and
  5447. (select o_result from checkrightsfortask(:i_id_employer, t.id)) = 1
  5448. into :task_name,
  5449. :taskid,
  5450. :taskstartdate,
  5451. :taskenddate,
  5452. :state,
  5453. :proj_id,
  5454. :isrejected,
  5455. :isstarted,
  5456. :curr_action,
  5457. :act_first,
  5458. :adate,
  5459. :act_empid,
  5460. :name,
  5461. :isboss
  5462. do
  5463. suspend;
  5464. end
  5465. suspend;
  5466. end
  5467. end
  5468. end^
  5469. SET TERM ; ^
  5470. commit;
  5471. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  5472. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  5473.  
  5474. /*------------------------------------------------------------------------------------------------------------------------------*/
  5475. /* Добавление столбца EXECTIME в таблицу DOCUMENTTEMPLATE*/
  5476. /*------------------------------------------------------------------------------------------------------------------------------*/
  5477.  
  5478. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('DOCUMENTTEMPLATE', 'EXECTIME', 'TIMESTAMP');
  5479.  
  5480. RESULT
  5481. =======
  5482. 0
  5483.  
  5484. commit;
  5485.  
  5486. /*------------------------------------------------------------------------------------------------------------------------------*/
  5487. /* Процедура для втавки актуального уровня в поле IS_CURRENT в таблице ROUTETREES */
  5488. /*------------------------------------------------------------------------------------------------------------------------------*/
  5489.  
  5490. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST_D('ROUTETREES', 'IS_CURRENT', 'INTEGER', '0');
  5491.  
  5492. RESULT
  5493. =======
  5494. 1
  5495.  
  5496. commit;
  5497.  
  5498. SET TERM ^ ;
  5499. CREATE PROCEDURE INSERTROUTEACTUALLEVELS
  5500. AS
  5501. declare variable idtask integer;
  5502. declare variable iscurrent integer;
  5503. declare variable iddocument integer;
  5504. declare variable r_stage integer;
  5505. declare variable current_doc integer;
  5506. declare variable is_exist smallint;
  5507. BEGIN
  5508. select count(is_current) from ROUTETREES where is_current > 0
  5509. into :is_exist;
  5510. if(is_exist = 0) then
  5511. BEGIN
  5512. current_doc=0;
  5513. for select max(stage) as stage, id_document from ROUTETREES
  5514. group by id_document
  5515. into :r_stage, :iddocument
  5516. DO
  5517. BEGIN
  5518. if(current_doc<>:iddocument) then
  5519. BEGIN
  5520. update ROUTETREES set is_current=0 where id_document=:iddocument;
  5521. select first 1 id_task from routetrees rt, task t
  5522. where rt.ID_TASK=t.ID and t.STATE=0 and rt.ID_DOCUMENT=:iddocument and rt.STAGE=:r_stage
  5523. into :idtask;
  5524.  
  5525. update ROUTETREES set is_current=1 where id_task=:idtask and id_document=:iddocument and stage=:r_stage;
  5526. current_doc=iddocument;
  5527.  
  5528. END
  5529. END
  5530. END
  5531. END ^
  5532. SET TERM ; ^
  5533.  
  5534. EXECUTE PROCEDURE INSERTROUTEACTUALLEVELS;
  5535. commit;
  5536.  
  5537. DROP PROCEDURE INSERTROUTEACTUALLEVELS;
  5538. commit;
  5539. /*------------------------------------------------------------------------------------*/
  5540. /*stasy - avto dobavlenie postanovchika v zadachi v raznie roly
  5541. nachalo*/
  5542. /*------------------------------------------------------------------------------------*/
  5543. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('TASK_TEMPLATES', 'REALAUTHOR_AS_AUTHOR', 'SMALLINT');
  5544.  
  5545. RESULT
  5546. =======
  5547. 1
  5548.  
  5549. commit;
  5550. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('TASK_TEMPLATES', 'REALAUTHOR_AS_RESPPERSON', 'SMALLINT');
  5551.  
  5552. RESULT
  5553. =======
  5554. 1
  5555.  
  5556. commit;
  5557. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('TASK_TEMPLATES', 'REALAUTHOR_AS_CONTROLER', 'SMALLINT');
  5558.  
  5559. RESULT
  5560. =======
  5561. 1
  5562.  
  5563. commit;
  5564. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('TASK_TEMPLATES', 'REALAUTHOR_AS_WORKER', 'SMALLINT');
  5565.  
  5566. RESULT
  5567. =======
  5568. 1
  5569.  
  5570. commit;
  5571. /*------------------------------------------------------------------------------------*/
  5572. /*konec*/
  5573. /*------------------------------------------------------------------------------------*/
  5574. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  5575. /*stasy & Elena: drop hlam*/
  5576. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  5577. delete from menuitems m where m.dmess_tagname = 'L_OPTIONS_DOCPREFS3' and m.item_id = 889;
  5578. commit;
  5579. delete from employer_settings where settings_key='DOCUMENT_PREFS_DEFAULT_SETTINGS';
  5580. commit;
  5581. delete from notification_prefs np where np.task_attribute = 2;
  5582. commit;
  5583. /* Delete search menu items */
  5584. delete from menuitems m where m.item_id in (951, 952, 953, 954, 955, 956) or m.dmess_tagname = 'L_GLOBAL_SEARCH';
  5585. commit;
  5586. /*-----------------------------------------------------------------------------------------------------------------------------------------------*/
  5587. /*stasy - opoveshenie o vipolnenii kt*/
  5588. /*------------------------------------------------------------------------------------*/
  5589. SET TERM ^ ;
  5590. CREATE OR ALTER PROCEDURE TMP_KT_READY_NOTIFI
  5591. AS
  5592. declare variable is_exist smallint;
  5593. BEGIN
  5594. select count (np.task_attribute) from notification_prefs np where id_employer=0 and action_type = 20
  5595. INTO :is_exist;
  5596.  
  5597. IF (is_exist > 0) THEN exit;
  5598.  
  5599. INSERT INTO NOTIFICATION_PREFS
  5600. (ACTION_TYPE, TASK_ATTRIBUTE, ID_EMPLOYER, SMS, MAIL, SMS_DISABLE, MAIL_DISABLE, EDITION)
  5601. VALUES (20, 1, 0, 1, 1, 0, 0, NULL);
  5602.  
  5603. INSERT INTO NOTIFICATION_PREFS
  5604. (ACTION_TYPE, TASK_ATTRIBUTE, ID_EMPLOYER, SMS, MAIL, SMS_DISABLE, MAIL_DISABLE, EDITION)
  5605. VALUES (20, 3, 0, 1, 1, 0, 0, NULL);
  5606.  
  5607. INSERT INTO NOTIFICATION_PREFS
  5608. (ACTION_TYPE, TASK_ATTRIBUTE, ID_EMPLOYER, SMS, MAIL, SMS_DISABLE, MAIL_DISABLE, EDITION)
  5609. VALUES (20, 4, 0, 1, 1, 0, 0, NULL);
  5610.  
  5611. INSERT INTO NOTIFICATION_PREFS
  5612. (ACTION_TYPE, TASK_ATTRIBUTE, ID_EMPLOYER, SMS, MAIL, SMS_DISABLE, MAIL_DISABLE, EDITION)
  5613. VALUES (20, 5, 0, 1, 1, 0, 0, NULL);
  5614.  
  5615. INSERT INTO NOTIFICATION_PREFS
  5616. (ACTION_TYPE, TASK_ATTRIBUTE, ID_EMPLOYER, SMS, MAIL, SMS_DISABLE, MAIL_DISABLE, EDITION)
  5617. VALUES (20, 6, 0, 1, 1, 0, 0, NULL);
  5618.  
  5619. INSERT INTO NOTIFICATION_PREFS
  5620. (ACTION_TYPE, TASK_ATTRIBUTE, ID_EMPLOYER, SMS, MAIL, SMS_DISABLE, MAIL_DISABLE, EDITION)
  5621. VALUES (20, 7, 0, 1, 1, 0, 0, NULL);
  5622.  
  5623. INSERT INTO NOTIFICATION_PREFS
  5624. (ACTION_TYPE, TASK_ATTRIBUTE, ID_EMPLOYER, SMS, MAIL, SMS_DISABLE, MAIL_DISABLE, EDITION)
  5625. VALUES (20, 8, 0, 1, 1, 0, 0, NULL);
  5626.  
  5627.  
  5628. END ^
  5629. SET TERM ; ^
  5630. commit;
  5631. EXECUTE PROCEDURE TMP_KT_READY_NOTIFI;
  5632. commit;
  5633. DROP PROCEDURE TMP_KT_READY_NOTIFI;
  5634. commit;
  5635. /*------------------------------------------------------------------------------------*/
  5636. /*stasy - opoveshenie o vipolnenii kt - conec*/
  5637. /*------------------------------------------------------------------------------------*/
  5638. /*stasy - procedura proveraet, javlaetsy li odna zapis' spravochnika potomkom drugoy*/
  5639. /*------------------------------------------------------------------------------------*/
  5640. SET TERM ^ ;
  5641. CREATE OR ALTER PROCEDURE IS_PARENT_CHILDE_RECORD (
  5642. i_childe integer,
  5643. i_parent integer)
  5644. returns (
  5645. o_result integer)
  5646. as
  5647. declare variable temp_childe integer;
  5648. declare variable temp_perent integer;
  5649. begin
  5650. for select id_parent from meta_record where id = :i_childe
  5651. into :temp_perent
  5652. do
  5653. begin
  5654. if (:temp_perent = :i_parent) then
  5655. begin
  5656. o_result = 1;
  5657. suspend;
  5658. exit;
  5659. end
  5660. if (:temp_perent is null) then
  5661. begin
  5662. o_result = 0;
  5663. suspend;
  5664. exit;
  5665. end
  5666. select o_result from IS_PARENT_CHILDE_RECORD (:temp_perent, :i_parent)
  5667. into :o_result;
  5668. suspend;
  5669. end
  5670. end ^
  5671. SET TERM ; ^
  5672. commit;
  5673. /*------------------------------------------------------------------------------------*/
  5674. /*conec*/
  5675. /*------------------------------------------------------------------------------------*/
  5676. /*------------------------------------------------------------------------------------*/
  5677. /*stasy - indecsi dl'auskorenija otchetow*/
  5678. /*------------------------------------------------------------------------------------*/
  5679. EXECUTE PROCEDURE ADD_INDEX_IF_DOES_NOT_EXIST('DDOCUMENT_REPORTS_INDEX_1', 'DOCUMENTS', 'ISDELETED,STATE,REGDATE');
  5680.  
  5681. RESULT
  5682. =======
  5683. 0
  5684.  
  5685. commit;
  5686. EXECUTE PROCEDURE ADD_INDEX_IF_DOES_NOT_EXIST('DOC_TASK_REPORTS_INDEX_1', 'GROUPTASK', 'TASK_ID_DOCUMENT, ID_EMPLOYER');
  5687.  
  5688. RESULT
  5689. =======
  5690. 0
  5691.  
  5692. commit;
  5693. /*------------------------------------------------------------------------------------*/
  5694. /*------------------------------------------------------------------------------------*/
  5695. /*stasy - merzkiy trigger*/
  5696. /*------------------------------------------------------------------------------------*/
  5697. SET TERM ^ ;
  5698. CREATE OR ALTER PROCEDURE TMP_DROP_MERSKIY_TRIGGER
  5699. AS
  5700. declare variable is_exist smallint;
  5701. BEGIN
  5702. SELECT result FROM IS_TRIGGER_EXISTS('NOTICEVIEW_AU0')
  5703. INTO :is_exist;
  5704.  
  5705. IF (is_exist = 1) THEN
  5706. begin
  5707. EXECUTE STATEMENT
  5708. 'DROP TRIGGER NOTICEVIEW_AU0;';
  5709. end
  5710. END ^
  5711. SET TERM ; ^
  5712. commit;
  5713. EXECUTE PROCEDURE TMP_DROP_MERSKIY_TRIGGER;
  5714. commit;
  5715. DROP PROCEDURE TMP_DROP_MERSKIY_TRIGGER;
  5716. commit;
  5717. /*------------------------------------------------------------------------------------*/
  5718.  
  5719. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('NOTICEVIEW', 'ISDELETED', 'SMALLINT');
  5720.  
  5721. RESULT
  5722. =======
  5723. 1
  5724.  
  5725. commit;
  5726.  
  5727. /*---------------------------------------------------------------------------------*/
  5728. /*stasy - rasshirenniy obshii reestr*/
  5729. /*---------------------------------------------------------------------------------*/
  5730. SET TERM ^ ;
  5731. CREATE OR ALTER PROCEDURE GETTREE_ID_ONLI (
  5732. i_id integer)
  5733. returns (
  5734. o_id integer)
  5735. as
  5736. begin
  5737. O_ID = I_ID;
  5738. suspend;
  5739. for SELECT ID
  5740. FROM department d
  5741. WHERE PARENTID = :I_ID and isdeleted = 0
  5742. INTO :O_ID
  5743. do
  5744. begin
  5745. for SELECT o_id
  5746. FROM GETTREE_ID_ONLI (:O_ID)
  5747. INTO :O_ID
  5748. do
  5749. suspend;
  5750. end
  5751. end^
  5752.  
  5753. SET TERM ; ^
  5754. commit;
  5755.  
  5756. SET TERM ^ ;
  5757. CREATE OR ALTER PROCEDURE GET_FURIGHT_EMP_BY_DEP (
  5758. i_empid integer,
  5759. i_depid integer,
  5760. i_only_this_dep smallint)
  5761. returns (
  5762. o_id_department integer,
  5763. o_empid integer)
  5764. as
  5765. declare variable l_flag smallint;
  5766. declare variable l_depid integer;
  5767. begin
  5768.  
  5769. if (I_ONLY_THIS_DEP = 1) then
  5770. begin
  5771. for select id, e.id_department from employer e
  5772. join permission p on (p.id_boss = :i_empid and p.enabled = 1 and e.id = p.id_employer)
  5773. where e.id_department = :I_DEPID and
  5774. e.isdeleted = 0
  5775. into :O_EMPID,
  5776. :o_id_department
  5777. do
  5778. suspend;
  5779. end
  5780. else
  5781. for select gt.o_id from GETTREE_ID_ONLI (:I_DEPID) gt
  5782. join deppermission dp on ( dp.id_department = gt.o_id
  5783. and id_employer = :i_empid
  5784. and enabled = 1 )
  5785.  
  5786. INTO :L_DEPID
  5787. do
  5788. begin
  5789. begin
  5790.  
  5791. for select id, e.id_department from employer e
  5792. join permission p on (p.id_boss = :i_empid and p.enabled = 1 and e.id = p.id_employer)
  5793. where e.id_department = :L_DEPID and
  5794. e.isdeleted = 0
  5795. into :O_EMPID,
  5796. :o_id_department
  5797. do
  5798. suspend;
  5799.  
  5800. end
  5801.  
  5802. end
  5803. END^
  5804.  
  5805. SET TERM ; ^
  5806. commit;
  5807. /*--------------------------------------------------------------------------------------------------------*/
  5808. SET TERM ^ ;
  5809. CREATE OR ALTER PROCEDURE GETDOCUMENTS_REGISTRY (
  5810. i_id_employer integer,
  5811. i_id_department integer,
  5812. i_id_doctype integer,
  5813. i_only_thisdep smallint,
  5814. i_from_date timestamp,
  5815. i_to_date timestamp)
  5816. returns (
  5817. o_id_document integer,
  5818. o_createdate timestamp,
  5819. o_regdate timestamp,
  5820. o_state smallint,
  5821. o_taskid integer,
  5822. o_doc_version integer,
  5823. o_document_files varchar(30000))
  5824. as
  5825. declare variable l_rootdepid integer;
  5826. declare variable l_department integer;
  5827. begin
  5828. if (i_id_department is null) then
  5829. select id_department from employer where id = :i_id_employer
  5830. into :l_rootdepid;
  5831. else
  5832. l_rootdepid = :i_id_department;
  5833.  
  5834. begin
  5835.  
  5836. for select distinct d.id , (select first 1 g.id_task
  5837. from grouptask g
  5838. where g.task_id_document = d.id
  5839. and g.task_id_document <>0
  5840. and g.task_state = 0), d.id_department
  5841.  
  5842. from documents d
  5843. where d.id_department in (select o_id from GETTREE_ID_ONLI (:l_rootdepid))
  5844. and d.regdate >= :i_from_date
  5845. and d.regdate <= :i_to_date
  5846. and d.id_doctype = :I_ID_DOCTYPE
  5847. and
  5848. (
  5849. (d.id_author in (select p.id_employer
  5850. from permission p
  5851. where p.id_boss = :i_id_employer
  5852. and p.enabled = 1))
  5853. or
  5854. (d.id in (select distinct g.task_id_document
  5855. from grouptask g
  5856. where g.id_employer in
  5857. (select p.id_employer
  5858. from permission p
  5859. where p.id_boss = :i_id_employer
  5860. and p.enabled = 1)
  5861. and g.task_id_document <>0)
  5862. )
  5863. )
  5864.  
  5865.  
  5866.  
  5867.  
  5868. into :o_id_document,
  5869. :o_taskid,
  5870. :l_department
  5871.  
  5872. do
  5873. begin
  5874. if (i_only_thisdep = 0 or l_department = i_id_department)
  5875. then
  5876. begin
  5877. select
  5878. d.createdate,
  5879. d.regdate,
  5880. d.state,
  5881. d.doc_version
  5882.  
  5883. from documents d
  5884. where d.id=:o_id_document
  5885.  
  5886. into
  5887.  
  5888. :o_createdate,
  5889. :o_regdate,
  5890. :o_state,
  5891. :o_doc_version;
  5892.  
  5893. select o_document_files from get_doc_files_list(:o_id_document,0)
  5894. into :o_document_files;
  5895. suspend;
  5896.  
  5897. end
  5898. end
  5899. end
  5900.  
  5901. END^
  5902.  
  5903. SET TERM ; ^
  5904. commit;
  5905.  
  5906. /*-------------------------------------------------------------------------------------------------------------*/
  5907. /*ryazanova -----------dobavlenie v adresnyju knigy polzovatelej(292714)----------------------------------------*/
  5908. SET TERM ^ ;
  5909. CREATE OR ALTER PROCEDURE UPDATE_ADRESS_BOOK
  5910. AS
  5911. DECLARE VARIABLE lRecID INTEGER;
  5912. DECLARE VARIABLE lDepID INTEGER;
  5913. DECLARE VARIABLE lEmp_ID_Rec INTEGER;
  5914. BEGIN
  5915. FOR
  5916. select d.id_record, em.id_department, em.id_rec_dict
  5917. from employer em, dictionaryrecordtype d
  5918. where em.id_rec_dict = d.id_record and em.isdeleted = 0 and d.id_system = 0
  5919. and em.parentid is null and em.id_department is not null
  5920. INTO :lRecID, :lDepID, :lEmp_ID_Rec
  5921. DO
  5922. BEGIN
  5923. IF (:lRecID IS NOT NULL) THEN
  5924. BEGIN
  5925. UPDATE dictionaryrecordtype d
  5926. SET d.is_system = 1, d.id_system = :lDepID
  5927. WHERE d.id_record = :lRecID;
  5928. END
  5929. END
  5930. END
  5931. ^
  5932.  
  5933. SET TERM ; ^
  5934.  
  5935. EXECUTE PROCEDURE UPDATE_ADRESS_BOOK;
  5936. DROP PROCEDURE UPDATE_ADRESS_BOOK;
  5937. COMMIT;
  5938. /*-------------------------------------------------------------------------------------------------------------*/
  5939. /*------------------------------------------------------------------------------------*/
  5940. /*pmv: polya adresnoi knigi po ymolchaniy */
  5941. /*------------------------------------------------------------------------------------*/
  5942. SET TERM ^ ;
  5943.  
  5944. CREATE OR ALTER procedure SET_ADDRESS_BOOK
  5945. as
  5946. begin
  5947. IF (NOT EXISTS(SELECT
  5948. SETTINGS_VALUE
  5949. FROM EMPLOYER_SETTINGS where (ID_EMPLOYER is null) and (SETTINGS_KEY='table-contacts-grid-state'))) THEN
  5950. BEGIN
  5951. update EMPLOYER_SETTINGS set SETTINGS_VALUE='[{"dataIndex":"path","header":"","sortable":true,"type":1,"width":200,"id":0},{"dataIndex":"f38","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":1},{"dataIndex":"f39","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":2},{"dataIndex":"f40","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":3},{"dataIndex":"f41","header":"","sortable":true,"type":5,"width":90,"hidden":false,"id":4},{"dataIndex":"f42","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":5},{"dataIndex":"f43","header":"","sortable":true,"type":12,"width":20,"hidden":false,"id":6},{"dataIndex":"f44","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":7},{"dataIndex":"f45","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":8},{"dataIndex":"f46","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":9},{"dataIndex":"f47","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":10},{"dataIndex":"f48","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":11},{"dataIndex":"f49","header":"","sortable":true,"type":10,"width":200,"hidden":false,"id":12},{"dataIndex":"f50","header":"","sortable":true,"type":10,"width":200,"hidden":false,"id":13},{"dataIndex":"f51","header":"","sortable":true,"type":10,"width":200,"hidden":false,"id":14},{"dataIndex":"f52","header":"","sortable":true,"type":11,"width":200,"hidden":false,"id":15},{"dataIndex":"f53","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":16},{"dataIndex":"f54","header":"","sortable":true,"type":2,"width":200,"hidden":true,"id":17},{"dataIndex":"f122","header":"","sortable":true,"type":3,"width":100,"hidden":true,"id":18},{"dataIndex":"f123","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":19},{"dataIndex":"f124","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":20},{"dataIndex":"f125","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":21},{"dataIndex":"f126","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":22},{"dataIndex":"f127","header":"","sortable":true,"type":13,"width":200,"hidden":true,"id":23},{"dataIndex":"f128","header":"","sortable":true,"type":5,"width":90,"hidden":true,"id":24},{"dataIndex":"f149","header":"","sortable":true,"type":12,"width":20,"hidden":true,"id":33},{"dataIndex":"f140","header":"","sortable":true,"type":8,"width":200,"hidden":true,"id":30},{"dataIndex":"f131","header":"","sortable":true,"type":11,"width":200,"hidden":true,"id":25},{"dataIndex":"f143","header":"","sortable":true,"type":10,"width":200,"hidden":true,"id":31},{"dataIndex":"f144","header":"","sortable":true,"type":2,"width":200,"hidden":true,"id":32},{"dataIndex":"f134","header":"","sortable":true,"type":4,"width":50,"hidden":true,"id":26},{"dataIndex":"f135","header":"","sortable":true,"type":3,"width":100,"hidden":true,"id":27},{"dataIndex":"f136","header":"","sortable":true,"type":6,"width":20,"hidden":true,"id":28},{"dataIndex":"f137","header":"","sortable":true,"type":9,"width":200,"hidden":true,"id":29},{"dataIndex":"f150","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":34},{"dataIndex":"f152","header":"","sortable":true,"type":12,"width":20,"hidden":true,"id":35}]' where (SETTINGS_KEY='table-contacts-grid-state') and (SETTINGS_VALUE='[{"dataIndex":"path","header":"","sortable":true,"type":1,"width":200,"id":0},{"dataIndex":"f38","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":1},{"dataIndex":"f39","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":2},{"dataIndex":"f40","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":3},{"dataIndex":"f41","header":"","sortable":true,"type":5,"width":90,"hidden":true,"id":4},{"dataIndex":"f42","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":5},{"dataIndex":"f43","header":"","sortable":true,"type":12,"width":20,"hidden":true,"id":6},{"dataIndex":"f44","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":7},{"dataIndex":"f45","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":8},{"dataIndex":"f46","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":9},{"dataIndex":"f47","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":10},{"dataIndex":"f48","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":11},{"dataIndex":"f49","header":"","sortable":true,"type":10,"width":200,"hidden":true,"id":12},{"dataIndex":"f50","header":"","sortable":true,"type":10,"width":200,"hidden":true,"id":13},{"dataIndex":"f51","header":"","sortable":true,"type":10,"width":200,"hidden":true,"id":14},{"dataIndex":"f52","header":"","sortable":true,"type":11,"width":200,"hidden":true,"id":15},{"dataIndex":"f53","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":16},{"dataIndex":"f54","header":"","sortable":true,"type":2,"width":200,"hidden":true,"id":17},{"dataIndex":"f122","header":"","sortable":true,"type":3,"width":100,"hidden":true,"id":18},{"dataIndex":"f123","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":19},{"dataIndex":"f124","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":20},{"dataIndex":"f125","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":21},{"dataIndex":"f126","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":22},{"dataIndex":"f127","header":"","sortable":true,"type":13,"width":200,"hidden":true,"id":23},{"dataIndex":"f128","header":"","sortable":true,"type":5,"width":90,"hidden":true,"id":24},{"dataIndex":"f149","header":"","sortable":true,"type":12,"width":20,"hidden":true,"id":33},{"dataIndex":"f140","header":"","sortable":true,"type":8,"width":200,"hidden":true,"id":30},{"dataIndex":"f131","header":"","sortable":true,"type":11,"width":200,"hidden":true,"id":25},{"dataIndex":"f143","header":"","sortable":true,"type":10,"width":200,"hidden":true,"id":31},{"dataIndex":"f144","header":"","sortable":true,"type":2,"width":200,"hidden":true,"id":32},{"dataIndex":"f134","header":"","sortable":true,"type":4,"width":50,"hidden":true,"id":26},{"dataIndex":"f135","header":"","sortable":true,"type":3,"width":100,"hidden":true,"id":27},{"dataIndex":"f136","header":"","sortable":true,"type":6,"width":20,"hidden":true,"id":28},{"dataIndex":"f137","header":"","sortable":true,"type":9,"width":200,"hidden":true,"id":29},{"dataIndex":"f150","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":34},{"dataIndex":"f152","header":"","sortable":true,"type":12,"width":20,"hidden":true,"id":35}]');
  5952. INSERT INTO EMPLOYER_SETTINGS(SETTINGS_KEY, SETTINGS_VALUE) values ('table-contacts-grid-state', '[{"dataIndex":"path","header":"","sortable":true,"type":1,"width":200,"id":0},{"dataIndex":"f38","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":1},{"dataIndex":"f39","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":2},{"dataIndex":"f40","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":3},{"dataIndex":"f41","header":"","sortable":true,"type":5,"width":90,"hidden":false,"id":4},{"dataIndex":"f42","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":5},{"dataIndex":"f43","header":"","sortable":true,"type":12,"width":20,"hidden":false,"id":6},{"dataIndex":"f44","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":7},{"dataIndex":"f45","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":8},{"dataIndex":"f46","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":9},{"dataIndex":"f47","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":10},{"dataIndex":"f48","header":"","sortable":true,"type":1,"width":200,"hidden":false,"id":11},{"dataIndex":"f49","header":"","sortable":true,"type":10,"width":200,"hidden":false,"id":12},{"dataIndex":"f50","header":"","sortable":true,"type":10,"width":200,"hidden":false,"id":13},{"dataIndex":"f51","header":"","sortable":true,"type":10,"width":200,"hidden":false,"id":14},{"dataIndex":"f52","header":"","sortable":true,"type":11,"width":200,"hidden":false,"id":15},{"dataIndex":"f53","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":16},{"dataIndex":"f54","header":"","sortable":true,"type":2,"width":200,"hidden":true,"id":17},{"dataIndex":"f122","header":"","sortable":true,"type":3,"width":100,"hidden":true,"id":18},{"dataIndex":"f123","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":19},{"dataIndex":"f124","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":20},{"dataIndex":"f125","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":21},{"dataIndex":"f126","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":22},{"dataIndex":"f127","header":"","sortable":true,"type":13,"width":200,"hidden":true,"id":23},{"dataIndex":"f128","header":"","sortable":true,"type":5,"width":90,"hidden":true,"id":24},{"dataIndex":"f149","header":"","sortable":true,"type":12,"width":20,"hidden":true,"id":33},{"dataIndex":"f140","header":"","sortable":true,"type":8,"width":200,"hidden":true,"id":30},{"dataIndex":"f131","header":"","sortable":true,"type":11,"width":200,"hidden":true,"id":25},{"dataIndex":"f143","header":"","sortable":true,"type":10,"width":200,"hidden":true,"id":31},{"dataIndex":"f144","header":"","sortable":true,"type":2,"width":200,"hidden":true,"id":32},{"dataIndex":"f134","header":"","sortable":true,"type":4,"width":50,"hidden":true,"id":26},{"dataIndex":"f135","header":"","sortable":true,"type":3,"width":100,"hidden":true,"id":27},{"dataIndex":"f136","header":"","sortable":true,"type":6,"width":20,"hidden":true,"id":28},{"dataIndex":"f137","header":"","sortable":true,"type":9,"width":200,"hidden":true,"id":29},{"dataIndex":"f150","header":"","sortable":true,"type":1,"width":200,"hidden":true,"id":34},{"dataIndex":"f152","header":"","sortable":true,"type":12,"width":20,"hidden":true,"id":35}]');
  5953. END
  5954. suspend;
  5955. end
  5956. ^
  5957.  
  5958. SET TERM ; ^
  5959. commit;
  5960. execute procedure set_address_book;
  5961. commit;
  5962. drop procedure set_address_book;
  5963. commit;
  5964. /*-------------------------------------------------------------------------------------------------------------*/
  5965.  
  5966. /*valer00n: Сортировка папок библиотеки по типам*/
  5967. SET TERM ^ ;
  5968. ALTER PROCEDURE GET_DL_USERTREE (
  5969. I_ID_PARENT Integer,
  5970. I_LEVEL Integer,
  5971. EMPID Integer )
  5972. RETURNS (
  5973. O_ID Integer,
  5974. O_NAME Varchar(200),
  5975. O_LEVEL Integer,
  5976. O_RIGHTS Integer,
  5977. O_OBJ_TYPE Integer )
  5978. AS
  5979. DECLARE VARIABLE L_SUB_RIGHT SMALLINT;
  5980. DECLARE VARIABLE L_NEXT_LEVEL SMALLINT;
  5981. begin
  5982. L_NEXT_LEVEL=:i_level;
  5983. for select df.ID, df.NAME,dp.rights,dp.issubrights, df.OBJ_TYPE
  5984. from DLFOLDER df
  5985. join dlpermissions dp on (dp.id_dlfolder=df.id and dp.id_employer=:EMPID)
  5986. where df.isdeleted =0 and df.parentid=:I_ID_PARENT order by df.OBJ_TYPE,df.name
  5987. into :o_id,:o_name,:O_RIGHTS,:l_sub_right,:o_obj_type
  5988. do
  5989. begin
  5990. L_NEXT_LEVEL=:i_level;
  5991. if (:O_RIGHTS>0) then
  5992. begin
  5993. L_NEXT_LEVEL=:i_level+1;
  5994. o_level=:i_level;
  5995. suspend;
  5996. end
  5997. if (:O_RIGHTS>0 or :l_sub_right>0) then
  5998. begin
  5999. for select gdlt.o_id,gdlt.o_name,gdlt.o_level,gdlt.o_rights, gdlt.o_obj_type
  6000. from get_dl_usertree(:o_id,:l_next_level,:empid) gdlt
  6001. into :o_id,:o_name,:o_level,:o_rights,:o_obj_type
  6002. do
  6003. suspend;
  6004. end
  6005. end
  6006. end^
  6007. SET TERM ; ^
  6008. commit;
  6009.  
  6010. SET TERM ^ ;
  6011. ALTER PROCEDURE GETDLPERMTREE_FOR_EMPLOYER (
  6012. I_ID Integer )
  6013. RETURNS (
  6014. O_ID Integer,
  6015. O_NAME Varchar(2000),
  6016. O_LEVEL Integer,
  6017. RIGHTS Integer,
  6018. O_OBJ_TYPE Integer )
  6019. AS
  6020. DECLARE VARIABLE L_ROOTDEP INTEGER;
  6021. DECLARE VARIABLE L_ROOTDEP_NAME INTEGER;
  6022. DECLARE VARIABLE START_LEVEL INTEGER;
  6023. DECLARE VARIABLE IS_ADMIN INTEGER;
  6024. DECLARE VARIABLE ADMIN_DEP INTEGER;
  6025. begin
  6026. select id
  6027. from dlfolder
  6028. where parentid = 0
  6029. and isdeleted<>1
  6030. into :L_ROOTDEP;
  6031.  
  6032. select O_RESULT from GET_RIGHT_EMPLOYER_AND_GROUP(:I_ID,7,0) into :is_admin;
  6033.  
  6034. /* if (is_admin=1) then
  6035. begin
  6036. SELECT id, name, 0, 0
  6037. from dlfolder
  6038. where parentid = 0
  6039. and isdeleted<>1
  6040. into :O_ID, :O_NAME, :O_LEVEL, :RIGHTS;
  6041. suspend;
  6042.  
  6043. for
  6044. SELECT o_id, o_name, o_level,O_RIGHTS FROM GETDLOLDTREE(:L_ROOTDEP, 1, :I_ID)
  6045. INTO :O_ID, :O_NAME, :O_LEVEL,:RIGHTS
  6046. do
  6047. suspend;
  6048.  
  6049. select d.id from employer e join dlfolder d on d.id_obj=e.id_department
  6050. where e.id=:i_id and d.isdeleted=0 and d.obj_type=1 into :admin_dep;
  6051.  
  6052.  
  6053. SELECT id, name, 1, 0
  6054. from dlfolder d
  6055. where d.id=:admin_dep
  6056. into :O_ID, :O_NAME, :O_LEVEL, :RIGHTS;
  6057. suspend;
  6058. RIGHTS=3;
  6059. for
  6060. SELECT o_id, o_name, o_level FROM GETDLSYSTREE(:admin_dep, 1)
  6061. INTO :O_ID, :O_NAME, :O_LEVEL
  6062. do
  6063. suspend;
  6064.  
  6065. end
  6066. else begin */
  6067. for
  6068. SELECT o_id, o_name, o_level,O_RIGHTS,O_OBJ_TYPE FROM GET_DL_USERTREE(0, 0, :I_ID)
  6069. INTO :O_ID, :O_NAME, :O_LEVEL,:RIGHTS,:O_OBJ_TYPE
  6070. do
  6071. suspend;
  6072. --end
  6073. end^
  6074. SET TERM ; ^
  6075. commit;
  6076. /*------------------------------------------------------------*/
  6077.  
  6078. /*-------------------------------------------------------------------------------------------------------------*/
  6079. /*kos: edited the trigger for tasks and - close and deleted project*/
  6080. /*--------------------------------------------------------------------------------------------------------------*/
  6081. SET TERM ^ ;
  6082.  
  6083. CREATE OR ALTER trigger task_au0 for task
  6084. active before update position 0
  6085. as
  6086. declare variable task_id int;
  6087. declare variable task_count int;
  6088. declare variable l_idroutetree integer;
  6089. declare variable l_idemployer integer;
  6090. declare variable l_idnotice integer;
  6091. declare variable l_id_docexec integer;
  6092. declare variable l_task_valuation_id integer;
  6093. begin
  6094. --закрывается без доклада
  6095. if (new.iswithreport = 0 and old.state = 0 and new.state = 1) then new.tsreport = 'now';
  6096. --задача с докладом
  6097. if (new.iswithreport = 1) then
  6098. begin
  6099. --доклад отправлен, но задача не закрыта
  6100. if (old.isreported=0 and new.isreported=1 and new.state = 0) then
  6101. new.respp_report = 'now';
  6102. --задача закрыта
  6103. if (old.state = 0 and new.state = 1) then
  6104. new.tsreport = 'now';
  6105. --возвращена на доработку
  6106. if (old.isreported=1 and new.isreported=0 and new.state = 0) then
  6107. new.respp_report = null;
  6108. end
  6109. if (new.isdeleted=1 and old.isdeleted =0) then
  6110. begin
  6111. update attachment set isdeleted = 1
  6112. where id_task=new.id;
  6113. end
  6114. if (new.isdeleted=1 and old.isdeleted =0) then
  6115. begin
  6116. update attachment set isdeleted = 1
  6117. where id_task=new.id;
  6118. end
  6119. /* меняем task_state в grouptask */
  6120. update grouptask set task_state=new.state
  6121. where id_task=new.id and (task_state != new.state or task_state is null);
  6122. if (new.state =1 and old.state = 0) then /*закрытие задачи - снимаем с контроля*/
  6123. begin
  6124. delete from hiddentasks where id_task=new.id;
  6125. select count (id) from task
  6126. where id_project =old.id_project
  6127. and state= 0
  6128. into :task_count;
  6129. /*напоминания*/
  6130. for select n.id from notice n where n.id_task = new.id
  6131. into :l_idnotice do
  6132. begin
  6133. execute procedure delete_notice(:l_idnotice);
  6134. end
  6135.  
  6136. end
  6137. if (new.state = 0 and old.state = 1) then /*восстановление задачи + проект*/
  6138. begin
  6139. update project set state=0
  6140. where id=new.id_project and state!=0;
  6141. new.id_valuation=null;/*сбрасываем точку восстановленной*/
  6142. update grouptask gt set gt.is_viewed_task=0 where gt.id_task=new.id;
  6143. update actions a set a.examinated=0 where a.examinated=1 and a.id_task=new.id;
  6144. end
  6145. end
  6146. ^
  6147.  
  6148. SET TERM ; ^
  6149. COMMIT;
  6150.  
  6151. SET TERM ^ ;
  6152.  
  6153. CREATE OR ALTER trigger department_bu0 for department
  6154. active before update position 0
  6155. as
  6156. declare variable newname varchar (200);
  6157. declare variable l_count integer;
  6158. begin
  6159. if (new.isdeleted = 1 and old.isdeleted = 0) then
  6160. begin
  6161. update employer
  6162. set isdeleted =1
  6163. where id_department = new.id;
  6164. end
  6165. if (new.name <> old.name) then
  6166. begin
  6167. newname = new.name || ': {L_GLOBAL_TASK_OUTOFPROJ}';
  6168. update project set name = :newname
  6169. where ID_Department = new.id and istrash = 1;
  6170. end
  6171. end
  6172. ^
  6173.  
  6174. SET TERM ; ^
  6175. COMMIT;
  6176. /*-------------------------------------------------------------------------------------------------------------*/
  6177.  
  6178. EXECUTE PROCEDURE ADD_INDEX_IF_DOES_NOT_EXIST('NOTICE_IDX5', 'NOTICE', 'ISDELETED');
  6179.  
  6180. RESULT
  6181. =======
  6182. 1
  6183.  
  6184. commit;
  6185.  
  6186. EXECUTE PROCEDURE ADD_INDEX_IF_DOES_NOT_EXIST('GROUPTASK_IDX2', 'GROUPTASK', 'ID_ORIGINAL, IS_HIDDEN_TASK, SHOW_TASK_DATE');
  6187.  
  6188. RESULT
  6189. =======
  6190. 1
  6191.  
  6192. commit;
  6193.  
  6194. /*-------------------------------------------------------------------------------------------------------------*/
  6195. /* Alisa Kotova, svetograd.motiw.ru task 6675 - get arcive documents by type and registration date*/
  6196. SET TERM ^ ;
  6197. CREATE OR ALTER PROCEDURE GETDOCUMENTS_ARCHIVE_MY (
  6198. I_EMPLOYER_ID Integer,
  6199. I_REGDATE_FROM Timestamp,
  6200. I_REGDATE_TO Timestamp )
  6201. RETURNS (
  6202. O_DOC_TYPE Integer,
  6203. O_DOCID Integer,
  6204. O_IS_RIGHT_ARHIV Integer )
  6205. AS
  6206. declare variable is_emplouer integer; /*есть права на автора*/
  6207. declare variable is_autor integer; /*есть права на участника задач по документу*/
  6208. begin
  6209. /*----------------------------------------------------------------------------------------*/
  6210. for select d.id, (select p.ID_Boss
  6211. from permission p
  6212. where p.ID_Boss = :i_employer_id
  6213. and p.ID_Employer = d.id_author
  6214. and p.enabled = 1
  6215. ), d.id_doctype
  6216. from documents d
  6217. where d.regdate >= :i_regdate_from and d.regdate <= :i_regdate_to
  6218. and d.state = 4 and d.isdeleted = 0
  6219. into :o_docid,
  6220. :is_autor,
  6221. :o_doc_type
  6222. do
  6223. /*----------------------------------------------------------------------------------------*/
  6224. /*если есть права на атора документа, то все, в архив попадает*/
  6225. if (is_autor <> 0) then
  6226. begin
  6227. O_IS_RIGHT_ARHIV = 1;
  6228. suspend;
  6229. end
  6230. /*----------------------------------------------------------------------------------------*/
  6231. /*если нет, проверяем права на участников задач по документу (с ботами блин)*/
  6232. else
  6233. begin
  6234. select count (g.task_id_document)
  6235. from grouptask g
  6236. where g.task_id_document = :o_docid
  6237. and g.id_employer in (select p.id_employer from permission p
  6238. where p.id_boss = :i_employer_id
  6239. and p.enabled = 1)
  6240. into :is_emplouer;
  6241. /*----------------------------------------------------------------------------------------*/
  6242. /*если подходящие задачи есть, то все ок, попадает в отчет*/
  6243. if (is_emplouer <> 0) then
  6244. begin
  6245. O_IS_RIGHT_ARHIV = 1;
  6246. end
  6247. /*----------------------------------------------------------------------------------------*/
  6248. /*если нет, то без вариантов - этого документа в отчете нет*/
  6249. else
  6250. begin
  6251. O_IS_RIGHT_ARHIV = 0;
  6252. end
  6253. suspend;
  6254. end
  6255. end^
  6256. SET TERM ; ^
  6257. commit;
  6258.  
  6259. GRANT EXECUTE
  6260. ON PROCEDURE GETDOCUMENTS_ARCHIVE_MY TO SYSDBA;
  6261. commit;
  6262.  
  6263. /* PM Kratkaya informaciya*/
  6264. EXECUTE PROCEDURE ADDMENUITEMBYTAG(903, 'L_MENU_BRIEF_INFO', '/user/hellopageuser/', 'L_ADDITIONAL', 3, 1, 0, NULL);
  6265. commit;
  6266.  
  6267. /* Unique attribute for doccard field */
  6268. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST_D('DOCCARDS', 'ISUNIQUE', 'SMALLINT', '0');
  6269.  
  6270. RESULT
  6271. =======
  6272. 1
  6273.  
  6274. commit;
  6275.  
  6276. /*ryazanova---Ispravit' nazvanija zadach IRG (6780)*/
  6277. update task t
  6278. set t.name = (select t1.name from task t1 where t1.id = t.parentid) || ' (' || t.irg_name || ')'
  6279. where t.is_isolated = 1 and t.irg_name <> '';
  6280. commit;
  6281. /*-------------------------------------------------------------------------------------------------------------------------------*/
  6282. /*ryazanova: derevo podrazdelenij v obratnom porjadke*/
  6283. SET TERM ^ ;
  6284. CREATE OR ALTER PROCEDURE get_backward_tree (
  6285. dep_id integer)
  6286. returns (
  6287. o_id integer)
  6288. as
  6289. DECLARE VARIABLE L_K SMALLINT;
  6290. begin
  6291. O_ID = :dep_id;
  6292. suspend;
  6293. for SELECT PARENTID
  6294. FROM department d
  6295. WHERE ID = :dep_id and isdeleted = 0
  6296. INTO :O_ID
  6297. do
  6298. begin
  6299. for SELECT o_id
  6300. FROM get_backward_tree (:O_ID)
  6301. INTO :O_ID
  6302. do
  6303. suspend;
  6304. end
  6305. end
  6306. ^
  6307. SET TERM ; ^
  6308.  
  6309. commit;
  6310. /*-------------------------------------------------------------------------------------------------------------------------------*/
  6311. /* Ryazanova - На ботов полномочия не удалять*/
  6312. SET TERM ^ ;
  6313.  
  6314. CREATE OR ALTER TRIGGER EMPLOYER_AU0 FOR EMPLOYER
  6315. ACTIVE AFTER UPDATE POSITION 0
  6316. as
  6317. declare variable bossid integer;
  6318. declare variable fbossid integer;
  6319. declare variable projid integer;
  6320. declare variable flag integer;
  6321. declare variable l_empid integer;
  6322. declare variable l_isdeleted integer;
  6323. declare variable l_enabled smallint;
  6324. declare variable l_parentid integer;
  6325. begin
  6326. if (new.isdeleted = 1 and old.isdeleted = 0) then
  6327. begin
  6328. /* for select id_boss
  6329. from permission
  6330. where id_employer = new.id and
  6331. enabled >0
  6332. into :l_empid
  6333. do
  6334. begin
  6335. select isdeleted from employer where id = :l_empid
  6336. into :l_isdeleted;
  6337. if (l_isdeleted=0) then
  6338. execute procedure set_permission_dep (l_empid, new.id);
  6339. end */
  6340.  
  6341. update permission
  6342. set enabled=0
  6343. where id_boss=new.id;
  6344.  
  6345. /* update permission
  6346. set enabled=0
  6347. where id_employer=new.id; */
  6348.  
  6349. /* Удаляем из всех пользовательских деревьев */
  6350. delete from ud_employer where id_employer=new.id;
  6351. end
  6352.  
  6353. if (new.isdeleted = 0 and old.isdeleted=1) then
  6354. execute procedure convertpermissions (new.id, new.isboss);
  6355.  
  6356. if (new.id_department != old.id_department) then
  6357. begin
  6358. for select distinct t.id_project
  6359. from grouptask gt
  6360. left join task t on (gt.id_task=t.id)
  6361. where gt.id_employer = old.id and gt.is_respperson=1
  6362. into :projid
  6363. do
  6364. begin
  6365. flag = null;
  6366. select count(id_project) from PROJECT_DEP
  6367. where id_Project = :projid and ID_Department = new.id_department
  6368. into :flag; /*проверяем не привязан ли уже этот проект к новому подразделению*/
  6369.  
  6370. if ((flag is null) or (flag = 0)) then /*если нет, то привязываем*/
  6371. insert into PROJECT_DEP (ID_Project, ID_Department)
  6372. values (:projid,new.id_department);
  6373.  
  6374. flag = null;
  6375. /* old begin */
  6376. /* select count (t.id) --проверяем остались ли еще задачи для этого проекта в старом подразделении
  6377. from task t
  6378. join employer e on t.id_employer = e.id
  6379. where t.id_project =:projid and
  6380. t.ID_employer != old.id and
  6381. e.id_department = old.id_department
  6382. into :flag;
  6383. */ /* old end */
  6384.  
  6385. /* new begin */
  6386. select count (t.id) /*проверяем остались ли еще задачи для этого проекта в старом подразделении*/
  6387. from task t
  6388. join grouptask gt on (t.id = gt.id_task and gt.is_worker = 1)
  6389. join employer e on gt.id_employer = e.id
  6390. where t.id_project =:projid and
  6391. gt.ID_employer != old.id and
  6392. e.id_department = old.id_department
  6393. into :flag;
  6394. /* new end */
  6395.  
  6396. if ((flag is null) or (flag = 0)) then /*если нет, то удаляем привязку этого проекта к подразделению*/
  6397. delete from PROJECT_DEP where
  6398. id_project = :projid and
  6399. id_department = old.id_department;
  6400. end
  6401.  
  6402. update permission
  6403. set enabled = 0
  6404. where id_boss = new.id and
  6405. is_manual=0;
  6406. execute procedure convertpermissions (new.id, new.isboss);
  6407. select parentid from employer where id = new.id
  6408. into :l_parentid;
  6409. /*Обновляем deppermission для боссов данного пользователя*/
  6410. for select id_boss,enabled
  6411. from permission
  6412. where id_employer = new.id and
  6413. enabled <> 0
  6414. into :l_empid,:l_enabled
  6415. do
  6416. begin
  6417. select isdeleted from employer where id = :l_empid
  6418. into :l_isdeleted;
  6419. if (l_isdeleted = 0) then
  6420. begin
  6421. /* Проверяем имеет ли начальник права на отдел в который перевели чела
  6422. * и если нет, то удаляем права начальника на чела
  6423. */
  6424. if (not (exists(select d.enabled
  6425. from deppermission d
  6426. where d.id_employer=:l_empid and
  6427. d.id_department = new.id_department and
  6428. d.enabled = :l_enabled)) and :l_empid <> :l_parentid) then
  6429. delete from permission p
  6430. where p.id_boss = :l_empid and
  6431. p.id_employer = new.id;
  6432. else
  6433. execute procedure set_permission_dep (l_empid, new.id);
  6434.  
  6435.  
  6436. /*Проверяем старое подразделение и удаляем его из deppermission, если там
  6437. больше нет пользователей, на которых босс имеет права*/
  6438. if (not exists(select p.id_boss
  6439. from permission p
  6440. join employer e on e.id = p.id_employer
  6441. where e.id_department = old.id_department and
  6442. p.id_boss = :l_empid and
  6443. enabled = :l_enabled)) then
  6444. begin
  6445. delete from deppermission
  6446. where id_department = old.id_department and
  6447. id_employer = :l_empid and
  6448. enabled = :l_enabled;
  6449. end
  6450. end
  6451. end
  6452.  
  6453. end
  6454.  
  6455. if (old.isboss <> new.isboss) then /*смена статуса сотрудника, переделываем полномочия*/
  6456. execute procedure convertpermissions (new.id, new.isboss);
  6457.  
  6458. if (old.pass <> new.pass and old.needpasswordchange = new.needpasswordchange) then
  6459. update employer
  6460. set needpasswordchange = 0
  6461. where id = new.id;
  6462.  
  6463. if (old.name<>new.name or
  6464. old.isboss<>new.isboss or
  6465. old.login<>new.login or
  6466. old.pass<>new.pass or
  6467. old.isdeleted<>new.isdeleted or
  6468. old.email<>new.email or
  6469. old.cphone<>new.cphone or
  6470. old.workphone<>new.workphone or
  6471. old.birthdate<>new.birthdate or
  6472. old.postaddress<>new.postaddress or
  6473. old.homephone<>new.homephone or
  6474. old.cphone2<>new.cphone2 or
  6475. old.commnt<>new.commnt or
  6476. old.manpost<>new.manpost or
  6477. old.fastlogin<>new.fastlogin or
  6478. old.awayto<>new.awayto
  6479. ) then
  6480. update employer
  6481. set name = new.name,
  6482. isboss = new.isboss,
  6483. login = new.login,
  6484. pass = new.pass,
  6485. isdeleted = new.isdeleted,
  6486. email = new.email,
  6487. cphone = new.cphone,
  6488. workphone = new.workphone,
  6489. birthdate = new.birthdate,
  6490. postaddress = new.postaddress,
  6491. homephone = new.homephone,
  6492. cphone2 = new.cphone2,
  6493. commnt = new.commnt,
  6494. manpost = new.manpost,
  6495. fastlogin = new.fastlogin,
  6496. awayto=new.awayto
  6497. where parentid = new.id and
  6498. isdeleted = 0;
  6499. end^
  6500.  
  6501. SET TERM ; ^
  6502. commit;
  6503.  
  6504. /*-------------------------------------------------------------------------------------------------------------------------------*/
  6505.  
  6506. /* Priznak dostupa */
  6507. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('EMPLOYER', 'ACCESS_TOKEN', 'VARCHAR(32)');
  6508.  
  6509. RESULT
  6510. =======
  6511. 1
  6512.  
  6513. commit;
  6514.  
  6515. /* Srok deystviya priznaka dostupa */
  6516. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('EMPLOYER', 'EXPIRE_DATE', 'TIMESTAMP');
  6517.  
  6518. RESULT
  6519. =======
  6520. 1
  6521.  
  6522. commit;
  6523. /*--------------------------------------------------------------------------------------------------*/
  6524. /*stasy - prava na proekty nachalo*/
  6525. SET TERM ^ ;
  6526. CREATE OR ALTER PROCEDURE GETPROJECT (
  6527. i_id_employer integer,
  6528. i_show_doc_projects smallint)
  6529. returns (
  6530. o_id integer,
  6531. o_name varchar(200),
  6532. o_description varchar(2000),
  6533. o_startdate timestamp,
  6534. o_enddate timestamp,
  6535. o_depname varchar(2000))
  6536. as
  6537. begin
  6538. if (i_show_doc_projects = 1) then
  6539. begin
  6540. for select distinct d.name,
  6541. p.id,
  6542. p.name,
  6543. p.description,
  6544. p.startdate,
  6545. p.enddate
  6546. from project p
  6547. join department d on (p.id_department = d.id)
  6548. left join task t on (p.id = t.id_project)
  6549. where
  6550. p.isdeleted =0
  6551. and p.state = 0
  6552. --and p.id_document is null
  6553. and
  6554. (
  6555. p.id_author in (select id_employer from permission where id_boss = :i_id_employer and enabled=1)
  6556. or
  6557. t.id in
  6558. (select distinct g.id_task
  6559. from grouptask g
  6560. join task t on t.id=g.id_task
  6561. where g.id_original in
  6562. (select id_employer from permission where id_boss = :i_id_employer and enabled=1)
  6563. and t.isdeleted=0
  6564. and t.is_checkpoint is null
  6565. and (t.issecret=0 or g.id_task in (select id_task from grouptask where id_original = :i_id_employer)))
  6566. )
  6567. into :O_DEPNAME,
  6568. :O_ID,
  6569. :O_NAME,
  6570. :O_DESCRIPTION,
  6571. :O_STARTDATE,
  6572. :O_ENDDATE
  6573. do
  6574. suspend;
  6575. end
  6576. else
  6577. begin
  6578. for select distinct d.name,
  6579. p.id,
  6580. p.name,
  6581. p.description,
  6582. p.startdate,
  6583. p.enddate
  6584. from project p
  6585. join department d on (p.id_department = d.id)
  6586. left join task t on (p.id = t.id_project)
  6587. where
  6588. p.isdeleted =0
  6589. and p.state = 0
  6590. and p.id_document is null
  6591. and
  6592. (
  6593. p.id_author in (select id_employer from permission where id_boss = :i_id_employer and enabled=1)
  6594. or
  6595. t.id in
  6596. (select distinct g.id_task
  6597. from grouptask g
  6598. join task t on t.id=g.id_task
  6599. where g.id_original in
  6600. (select id_employer from permission where id_boss = :i_id_employer and enabled=1)
  6601. and t.isdeleted=0
  6602. and t.is_checkpoint is null
  6603. and (t.issecret=0 or g.id_task in (select id_task from grouptask where id_original = :i_id_employer)))
  6604. )
  6605. into :O_DEPNAME,
  6606. :O_ID,
  6607. :O_NAME,
  6608. :O_DESCRIPTION,
  6609. :O_STARTDATE,
  6610. :O_ENDDATE
  6611. do
  6612. suspend;
  6613. end
  6614. end^
  6615. Statement failed, SQLCODE = -206
  6616. Dynamic SQL Error
  6617. -SQL error code = -206
  6618. -Column unknown
  6619. -T.IS_CHECKPOINT
  6620. -At line 39, column 20
  6621. At line 5683 in file /tmp/patch_db/script
  6622. SET TERM ; ^
  6623.  
  6624. commit;
  6625.  
  6626. SET TERM ^ ;
  6627. CREATE OR ALTER PROCEDURE GETPROJECTARCHIVE (
  6628. i_id_employer integer)
  6629. returns (
  6630. o_id integer,
  6631. o_name varchar(200),
  6632. o_description varchar(2000),
  6633. o_startdate timestamp,
  6634. o_enddate timestamp,
  6635. o_depname varchar(2000))
  6636. as
  6637. begin
  6638.  
  6639. for select distinct p.id,
  6640. p.name,
  6641. p.description,
  6642. p.startdate,
  6643. p.enddate,
  6644. d.name
  6645. from project p
  6646. join department d on (p.id_department = d.id)
  6647. left join task t on (p.id = t.id_project)
  6648. where
  6649. p.isdeleted =0
  6650. and p.state = 1
  6651. and
  6652. (
  6653. p.id_author in (select id_employer from permission where id_boss = :i_id_employer and enabled=1)
  6654. or
  6655. t.id in
  6656. (select distinct g.id_task
  6657. from grouptask g
  6658. join task t on t.id=g.id_task
  6659. where g.id_original in
  6660. (select id_employer from permission where id_boss = :i_id_employer and enabled=1)
  6661. and t.isdeleted=0
  6662. and t.is_checkpoint is null
  6663. and (t.issecret=0 or g.id_task in (select id_task from grouptask where id_original = :i_id_employer)))
  6664. )
  6665. into :O_ID,
  6666. :O_NAME,
  6667. :O_DESCRIPTION,
  6668. :O_STARTDATE,
  6669. :O_ENDDATE,
  6670. :O_DEPNAME
  6671. do
  6672. suspend;
  6673. end^
  6674. Statement failed, SQLCODE = -206
  6675. Dynamic SQL Error
  6676. -SQL error code = -206
  6677. -Column unknown
  6678. -T.IS_CHECKPOINT
  6679. -At line 36, column 20
  6680. At line 5868 in file /tmp/patch_db/script
  6681. SET TERM ; ^
  6682.  
  6683. commit;
  6684.  
  6685.  
  6686. SET TERM ^ ;
  6687. CREATE OR ALTER PROCEDURE GETNAVIGATIONTREE_PROJ (
  6688. i_id_employer integer,
  6689. i_is_show_archive_projects smallint)
  6690. returns (
  6691. id integer,
  6692. name varchar(200),
  6693. description varchar(2000),
  6694. state smallint,
  6695. color varchar(16),
  6696. is_mark_by_color smallint)
  6697. as
  6698. declare variable l_mydepid integer;
  6699. BEGIN
  6700. select ID_Department from employer where id=:I_ID_EMPLOYER into :L_MYDEPID;
  6701. for select distinct p.id,
  6702. p.name,
  6703. p.description,
  6704. p.state,
  6705. p.color,
  6706. p.is_mark_by_color
  6707. from project p
  6708. left join task t on (p.id = t.id_project)
  6709. where
  6710. p.isdeleted =0
  6711. and (p.state = 0 or p.state = :i_is_show_archive_projects)
  6712. and
  6713. (
  6714. p.id_author in (select id_employer from permission where id_boss = :i_id_employer and enabled=1)
  6715. or
  6716. t.id in
  6717. (select distinct g.id_task
  6718. from grouptask g
  6719. join task t on t.id=g.id_task
  6720. where g.id_original in
  6721. (select id_employer from permission where id_boss = :i_id_employer and enabled=1)
  6722. and t.isdeleted=0
  6723. and t.is_checkpoint is null
  6724. and (t.issecret=0 or g.id_task in (select id_task from grouptask where id_original = :i_id_employer)))
  6725. )
  6726. INTO :ID,
  6727. :NAME,
  6728. :DESCRIPTION,
  6729. :STATE,
  6730. :color,
  6731. :is_mark_by_color
  6732. DO
  6733. BEGIN
  6734. SUSPEND;
  6735. END
  6736. END^
  6737. Statement failed, SQLCODE = -206
  6738. Dynamic SQL Error
  6739. -SQL error code = -206
  6740. -Column unknown
  6741. -T.IS_CHECKPOINT
  6742. -At line 37, column 20
  6743. At line 5975 in file /tmp/patch_db/script
  6744. SET TERM ; ^
  6745.  
  6746. commit;
  6747.  
  6748. /*stasy - prava na proekty conec*/
  6749.  
  6750. /* Добавление домена если такового еще нет.*/
  6751. SET TERM ^ ;
  6752. CREATE OR ALTER PROCEDURE CREATE_DOMAIN_IF_NOT_EXIST (
  6753. domain_name varchar(100),
  6754. sql_param_str varchar(300))
  6755. as
  6756. declare variable is_exist varchar(200);
  6757. BEGIN
  6758. SELECT RDB$FIELD_NAME FROM RDB$FIELDS WHERE UPPER( RDB$FIELD_NAME) = UPPER(:domain_name)
  6759. INTO :is_exist;
  6760.  
  6761. if (is_exist is null) THEN
  6762. BEGIN
  6763. EXECUTE STATEMENT
  6764. 'CREATE DOMAIN ' || UPPER(:domain_name)||' '|| :sql_param_str ;
  6765. END
  6766. END^
  6767. SET TERM ; ^
  6768. commit;
  6769. GRANT EXECUTE ON PROCEDURE CREATE_DOMAIN_IF_NOT_EXIST TO SYSDBA;
  6770. commit;
  6771.  
  6772. /* Создаем новый домен для хранения ЭЦП документов,заменяем тип поля в documents.signature*/
  6773. EXECUTE PROCEDURE CREATE_DOMAIN_IF_NOT_EXIST ('BLOB_4096', 'AS BLOB SUB_TYPE 1 SEGMENT SIZE 4096 CHARACTER SET WIN1251');
  6774. commit;
  6775. update RDB$RELATION_FIELDS set RDB$FIELD_SOURCE = 'BLOB_4096', RDB$COLLATION_ID = 0 where (RDB$FIELD_NAME = 'SIGNATURE') and (RDB$RELATION_NAME = 'DOCUMENTS');
  6776. commit;
  6777.  
  6778. SET TERM ^ ;
  6779.  
  6780. /*меняем строчку в вычислении признака issecretary - не учитывались псевдонимы*/
  6781. create or alter procedure INFORMER2_GETMYTASKS (
  6782. ID_EMPLOYER integer,
  6783. ATASKID integer,
  6784. MINTASKID integer)
  6785. returns (
  6786. TASKID integer,
  6787. TASKNAME varchar(2000),
  6788. ISVIEWED smallint,
  6789. ISGROUP smallint,
  6790. ISNEWMESSAGES smallint,
  6791. AMIAUTHOR smallint,
  6792. PRJID integer,
  6793. ISREPORTED smallint,
  6794. AUTHORID integer,
  6795. EMPID integer,
  6796. ISREJECTED smallint,
  6797. ISWITHREPORT smallint,
  6798. LASTACTID integer,
  6799. TASKDESC varchar(10000),
  6800. STARTDATE timestamp,
  6801. ENDDATE timestamp,
  6802. ACTCOUNT integer,
  6803. ATT varchar(24000),
  6804. TASK_TYPE smallint,
  6805. ORDERTYPE smallint,
  6806. DOCUMENTID integer,
  6807. PRIORITY smallint,
  6808. LASTACTDATE timestamp,
  6809. EMPSID varchar(5000),
  6810. DEPPATH varchar(2000),
  6811. STATE smallint,
  6812. LASTACT varchar(10000),
  6813. LASTACTEMPID integer,
  6814. ISONLYFORVIEW smallint,
  6815. USERID integer,
  6816. MYCOLOR smallint,
  6817. SEND_ACTIONS smallint,
  6818. RECEIVE_MAIL smallint,
  6819. RECEIVE_SMS smallint,
  6820. ACOUNT integer,
  6821. LASTACOUNT integer,
  6822. DOCUMENTNAME varchar(1000),
  6823. DOCUMENTTYPEID integer,
  6824. ISRESOLUTION smallint,
  6825. ID_REALAUTHOR integer,
  6826. ID_TASKINITIATOR integer,
  6827. DOCVERSION integer,
  6828. BTN varchar(200),
  6829. PARENTID integer,
  6830. SHOWDATE timestamp,
  6831. IDFOLDER integer,
  6832. ISSECRETARY smallint,
  6833. ISCONTROL smallint,
  6834. CTRLSID varchar(2000),
  6835. SIGNSID varchar(2000),
  6836. IS_HAVE_ISOLATED smallint,
  6837. SYSACTCOUNT integer,
  6838. MEANSACTCOUNT integer,
  6839. ID_CHECKPOINT integer,
  6840. ID_META_DICTIONARY integer,
  6841. NRECORD_TASKTYPE integer,
  6842. AUTHORSID varchar(2000),
  6843. MAINEMPSID varchar(2000),
  6844. NUMERATOR varchar(100),
  6845. ISSECRET smallint,
  6846. NEWACTCOUNT integer,
  6847. IS_COMMITED smallint,
  6848. CTRLID integer,
  6849. ID_LAST_VIEWED_ACT integer,
  6850. LASTCHANGE timestamp,
  6851. ISUSEPARENTDOCS smallint,
  6852. IS_SHOW_TASK smallint)
  6853. as
  6854. declare variable GT_LASTCHANGE timestamp;
  6855. declare variable TA_LASTCHANGE timestamp;
  6856. declare variable I integer;
  6857. declare variable CNT integer;
  6858. declare variable EXECDOCUMENTID varchar(1000);
  6859. declare variable L_ISHIDDEN integer;
  6860. declare variable SID integer;
  6861. begin
  6862. for select TASKID, TASKNAME, ISGROUP,
  6863. AMIAUTHOR, PRJID, IsReported,
  6864. /* AuthorId, EmpId, */IsRejected, IsWithReport,
  6865. taskdesc, startdate, enddate, task_type,
  6866. documentid, priority, deppath, state, IsOnlyForView, UserId, Send_Actions,
  6867. ExecDocumentId, ID_REALAUTHOR, ID_TASKINITIATOR, PARENTID, is_have_isolated, id_checkpoint
  6868. , id_meta_dictionary, nrecord_tasktype,numerator
  6869. from Informer2_Getmytasks1(:ID_EMPLOYER, :ATASKID)
  6870. into :TASKID, :TASKNAME, :ISGROUP,
  6871. :AMIAUTHOR, :PRJID, :IsReported,
  6872. /* :AuthorId, :EmpId,*/ :IsRejected, :IsWithReport,
  6873. :taskdesc, :startdate, :enddate, :task_type,
  6874. :documentid, :priority, :deppath, :state, :IsOnlyForView, :UserId, :Send_Actions,
  6875. :ExecDocumentId, :ID_REALAUTHOR, :ID_TASKINITIATOR,:PARENTID, :is_have_isolated, :id_checkpoint
  6876. ,:id_meta_dictionary, :nrecord_tasktype,:numerator
  6877. do
  6878. if (TaskId=ATaskId or TaskId>MinTaskId)
  6879. then begin
  6880. if (DocumentId is null and ExecDocumentId is null) then OrderType=0;
  6881. else
  6882. if (DocumentId is not null) then OrderType=1;
  6883. else
  6884. if (ExecDocumentId is not null)
  6885. then begin
  6886. OrderType=2;
  6887. DocumentId=ExecDocumentId;
  6888. end
  6889. ISNEWMESSAGES=0;
  6890. EXECUTE PROCEDURE informer2_gettaskids(ID_EMPLOYER, TASKID, IsOnlyForView) returning_values :EMPSID, :CTRLSID, :SIGNSID,
  6891. :AuthorId, :EmpId , :AUTHORSID , :MAINEMPSID, :CTRLID;
  6892. LastActDate=NULL;
  6893. LastActId=-1;
  6894. LastActId=-1;
  6895. ActCount=0;
  6896. LASTACT='';
  6897. LASTACTEMPID=-1;
  6898. idfolder=0;
  6899. newactcount=0;
  6900. MyColor=NULL;
  6901. cnt=NULL;
  6902. select ta.marker_color, ta.count_actions_view, ta.is_view_new_actions, ta.Id_last_viewed_action
  6903. from task_attributes ta
  6904. where ta.id_employer=:id_employer and
  6905. ta.id_task=:taskid
  6906. into :mycolor, :cnt, :ISNEWMESSAGES, :Id_last_viewed_act;
  6907. select o_result
  6908. from CheckTaskViewed(:ID_EMPLOYER, :taskid)
  6909. into :isviewed;
  6910. select t.la_id, t.action_count, t.sysaction_count, t.meansaction_count, t.issecret, t.isuseparentdocs
  6911. from Task t
  6912. where id= :TaskId
  6913. into :LastActId, :ActCount, :sysactcount, :meansactcount, :issecret, :isuseparentdocs;
  6914. if (isuseparentdocs=1) then
  6915. begin
  6916. SELECT O_DocumentID, O_DocumentName FROM getparentdocs(:TaskID)
  6917. into :Documentid, :Documentname;
  6918. end
  6919. if (ActCount is null) then ActCount=0;
  6920. ACount=ActCount;
  6921. if ((ISNEWMESSAGES=1)or(ISNEWMESSAGES is null)or :ActCount=0)
  6922. then ISNEWMESSAGES=0;
  6923. else ISNEWMESSAGES=1;
  6924. if (LastActId is null) then LastActId=0;
  6925. if (LastActId>0) then
  6926. begin
  6927. select adate, Name, ID_Employer
  6928. from Actions
  6929. where id= :LastActId
  6930. into :LastActDate, :LASTACT, :LASTACTEMPID;
  6931. end
  6932. execute procedure Informer2_TaskAtt(:taskid, -1, -1)
  6933. returning_values :att;
  6934.  
  6935. if (MyColor is null) then MyColor=0;
  6936. select O_RECIVE_SMS, O_RECIVE_MAIL
  6937. from GET_TASK_MAIL_SMS(:TaskId, :id_employer)
  6938. into :receive_sms, :receive_mail;
  6939.  
  6940. if (cnt is null) then lastacount=0;
  6941. else lastacount=cnt;
  6942. newactcount=acount-lastacount;
  6943. isresolution=null;
  6944. btn=null;
  6945. select first 1 rt.isresolution, rt.button_caption from routetrees rt
  6946. where rt.id_task = :taskid and
  6947. rt.isvirtual = 0 and
  6948. rt.isdeleted = 0 and
  6949. (exists(select id from routenode rn
  6950. where rn.id_routetree = rt.id and
  6951. rn.id_employer = :id_employer and
  6952. rn.isdeleted = 0))
  6953. into :isresolution, :btn;
  6954. if (isresolution is null) then isresolution=0;
  6955. DocumentName='';
  6956. DocumentTypeId=NULL;
  6957. DocVersion=NULL;
  6958. select Field1, ID_DocType, Doc_Version
  6959. from Documents
  6960. where id= :DocumentId
  6961. into :DocumentName, :DocumentTypeId, :DocVersion;
  6962. i=1;
  6963. if (OrderType=1) then
  6964. begin
  6965. select O_result from documentcommited (:id_employer, :taskid)
  6966. into :is_commited;
  6967. if (is_commited=1) then
  6968. if (not (exists(select first 1 id_task from grouptask where id_task=:TaskId and
  6969. id_employer=:ID_employer and is_controler=1)))
  6970. then i=0;
  6971. end
  6972. else is_commited=0;
  6973. if (IsOnlyForView is null) then IsOnlyForView=0;
  6974. if (IsOnlyForView=1) then
  6975. begin
  6976. /* SignsId=''; */
  6977. if (exists (select first 1 id
  6978. from Actions
  6979. where id_task=:TaskId and
  6980. examinated=1 and
  6981. (id_employer= :id_employer or id_employer in (select O_EMPLOYERID from
  6982.  
  6983. GETEMPLOYERALIASES(:id_employer)))
  6984. ))
  6985. then i=0;
  6986. else begin
  6987. i=1;
  6988. end
  6989. end
  6990. /*if user needs information by the only one task,
  6991. then return this task in any case*/
  6992. if ((i=0) and (ATASKID<>-1)) then i=1;
  6993. if (i=1) then
  6994. begin
  6995. showdate=NULL;
  6996. select gt.show_task_date
  6997. from grouptask gt
  6998. where gt.id_task=:taskid and gt.id_employer=:id_employer
  6999. into :showdate;
  7000.  
  7001. ISSECRETARY=0;
  7002. if (exists(select * from grouptask gr where gr.id_task=:TaskId
  7003. AND GR.id_original=:id_employer and gr.is_shadow=1)) then
  7004. ISSECRETARY=1;
  7005. --повесит пережитком
  7006. ISCONTROL=0;
  7007.  
  7008. SELECT
  7009. t.lastchange,
  7010. ta.lastchange,
  7011. gt.lastchange
  7012. FROM
  7013. task t
  7014. left join task_attributes ta on (ta.id_task = t.id and ta.id_employer = :id_employer)
  7015. left join grouptask gt on (gt.id_task = t.id and gt.id_employer = :id_employer)
  7016. WHERE
  7017. t.id = :taskid
  7018. INTO
  7019. :lastchange,
  7020. :ta_lastchange,
  7021. :gt_lastchange;
  7022.  
  7023. if (:ta_lastchange > :lastchange) then
  7024. begin
  7025. lastchange = :ta_lastchange;
  7026. end
  7027.  
  7028. if (:gt_lastchange > :lastchange) then
  7029. begin
  7030. lastchange = :gt_lastchange;
  7031. end
  7032.  
  7033. is_show_task = 0;
  7034.  
  7035. if (is_show_task = 0) then
  7036. begin
  7037.  
  7038. if (exists ( select
  7039. first (1) gt.id_task
  7040. from
  7041. grouptask gt
  7042. where
  7043. gt.id_task = :taskid and
  7044. (
  7045. gt.id_original = :id_employer OR
  7046. gt.id_original = (select parentid from employer where id = :id_employer)
  7047. )
  7048. and
  7049. (
  7050. gt.is_author = 1 OR
  7051. gt.is_respperson = 1 OR
  7052. gt.is_worker = 1 OR
  7053. gt.is_controler = 1 OR
  7054. gt.is_shadow = 1
  7055. )
  7056. )
  7057. )
  7058. then
  7059. is_show_task = 1;
  7060.  
  7061.  
  7062. if (is_show_task = 1) then
  7063. if (exists( select
  7064. first (1) gt.id_task
  7065. from
  7066. grouptask gt
  7067. join task t on
  7068. t.id = gt.id_task
  7069. where
  7070. gt.id_task = :taskid and
  7071. t.is_isolated = 1 and
  7072. (
  7073. gt.id_original = :id_employer OR
  7074. gt.id_original = (select parentid from employer where id = :id_employer)
  7075. )
  7076. and
  7077. (
  7078. gt.is_author = 1 OR
  7079. gt.is_respperson = 1 OR
  7080. gt.is_worker = 1 OR
  7081. gt.is_controler = 1 OR
  7082. gt.is_shadow = 1
  7083. )
  7084. and exists
  7085. (
  7086. select
  7087. first (1) id_task
  7088. from
  7089. grouptask
  7090. where
  7091. id_task = (select parentid from task where id = :taskid) and
  7092. (
  7093. id_original = :id_employer OR
  7094. id_original = (select parentid from employer where id = :id_employer)
  7095. )
  7096. and
  7097. (
  7098. is_author = 1 OR
  7099. is_respperson = 1 OR
  7100. is_worker = 1 OR
  7101. is_controler = 1 OR
  7102. is_shadow = 1
  7103. )
  7104. )
  7105. )
  7106. )
  7107. then
  7108. is_show_task = 0;
  7109.  
  7110. end
  7111.  
  7112. suspend;
  7113. end
  7114. end
  7115. end^
  7116.  
  7117. SET TERM ; ^
  7118.  
  7119. commit;INSERT INTO SETTINGS (SETTINGS_KEY,SETTINGS_VALUE) VALUES ('version','1.4.18');
  7120.  
  7121. update patch_info
  7122. set paramvalue = 'OK'
  7123. where paramname = 'PATCH_STATUS';
  7124. update patch_info
  7125. set paramvalue = '1.4.18'
  7126. where paramname = 'CURRENT_VERSION';
  7127. commit work;
  7128.  
  7129.  
  7130. commit;
  7131. commit work;
  7132.  
  7133. Use CONNECT or CREATE DATABASE to specify a database
  7134. CONNECT "/var/Motiw/db/motiw.fdb" USER 'SYSDBA' PASSWORD 'masterkey';
  7135.  
  7136. SET NAMES WIN1251;
  7137.  
  7138. SET TERM ^ ;
  7139. CREATE OR ALTER PROCEDURE ADD_GRAYSCALE_DAFAULT_PROFILE
  7140. AS
  7141. DECLARE VARIABLE l_employer_id INTEGER;
  7142. BEGIN
  7143. IF (NOT EXISTS(SELECT
  7144. id
  7145. FROM
  7146. employer_settings
  7147. WHERE
  7148. id_employer is null AND settings_key = 'COLORINDICATION_PROFILE_DEFAULT' AND settings_value LIKE 'Grayscale%')) THEN
  7149. BEGIN
  7150. /* добавляем новый профиль */
  7151. INSERT INTO employer_settings
  7152. (id_employer, settings_key, settings_value, tag)
  7153. VALUES
  7154. (null, 'COLORINDICATION_PROFILE_DEFAULT', 'Grayscale;FFFFFF:60:Только что;E6E6E6:480:Совсем недавно;B6B6B6:2880:Недавно;9A9A9A:7200:Средней давности;6A6A6A:14400:Давно;454545:20160:Довольно давно;000000:74880:Очень давно;FF0000:0:Вообще не было;', 1);
  7155. /* меняем старый */
  7156. UPDATE
  7157. employer_settings
  7158. SET
  7159. settings_value = 'Для пользователей;FF3333:0:Только что;FF9933:5:Совсем недавно;FFFF99:30:Недавно;00CC66:60:Средней давности;6699FF:300:Давно;0033CC:1440:Довольно давно;8000FF:10080:Очень давно;000000:0:Вообще не было;',
  7160. tag = 0
  7161. WHERE
  7162. id_employer is null AND settings_key = 'COLORINDICATION_PROFILE_DEFAULT' AND settings_value LIKE 'Для пользователей%';
  7163. END
  7164. END
  7165. ^
  7166. SET TERM ; ^
  7167. COMMIT;
  7168.  
  7169. EXECUTE PROCEDURE ADD_GRAYSCALE_DAFAULT_PROFILE;
  7170. COMMIT;
  7171.  
  7172. DROP PROCEDURE ADD_GRAYSCALE_DAFAULT_PROFILE;
  7173. COMMIT;
  7174.  
  7175. SET TERM ^ ;
  7176.  
  7177. ALTER PROCEDURE GETTASKINFO4SF (
  7178. idemployer integer,
  7179. idtask integer)
  7180. returns (
  7181. taskid integer,
  7182. tasknumber varchar(200),
  7183. priority integer,
  7184. taskname varchar(2000),
  7185. startdate date,
  7186. enddate date,
  7187. author varchar(10000),
  7188. controller varchar(10000),
  7189. responsible varchar(10000),
  7190. worker varchar(10000),
  7191. projectname varchar(10000),
  7192. tasktype varchar(10000),
  7193. taskstate char(4),
  7194. marker integer)
  7195. as
  7196. declare variable is_author smallint;
  7197. declare variable is_controller smallint;
  7198. declare variable is_responsible smallint;
  7199. declare variable is_worker smallint;
  7200. declare variable emp_name varchar(2000);
  7201. declare variable act_cnt integer;
  7202. declare variable istasknew smallint;
  7203. declare variable isactnew smallint;
  7204. declare variable isreport smallint;
  7205. declare variable isreject smallint;
  7206. declare variable i integer;
  7207. declare variable sql varchar(1000);
  7208. BEGIN
  7209. SQL = '';
  7210. if (idtask<>-1) then
  7211. begin
  7212. SQL = ' and t.ID = ' || :idtask;
  7213. end
  7214. for EXECUTE STATEMENT 'select
  7215. t.ID,
  7216. lower(t.NUMERATOR),
  7217. t.PRIORITY,
  7218. lower(t.NAME),
  7219. t.STARTDATE,
  7220. t.ENDDATE,
  7221. lower(p.NAME),
  7222. lower(md.NAME),
  7223. ta.MARKER_COLOR,
  7224. t.action_count,
  7225. (1 - gt.IS_VIEWED_TASK),
  7226. (1-(case ta.IS_VIEW_NEW_ACTIONS when (ta.IS_VIEW_NEW_ACTIONS) then ta.IS_VIEW_NEW_ACTIONS else 0 end)),
  7227. t.ISREPORTED,
  7228. t.ISREJECTED
  7229. from
  7230. TASK t
  7231. join GROUPTASK gt on
  7232. t.ID = gt.ID_TASK
  7233. join PROJECT p on
  7234. p.id = t.ID_PROJECT
  7235. join META_DICTIONARY md on
  7236. md.ID = t.ID_META_DICTIONARY
  7237. left join TASK_ATTRIBUTES ta on
  7238. ta.ID_TASK = gt.ID_TASK and ta.id_employer=gt.id_original
  7239. where
  7240. gt.id_original = ' || :idemployer || ' and gt.task_state=0' || :SQL
  7241. into
  7242. :TASKID,
  7243. :TASKNUMBER,
  7244. :PRIORITY,
  7245. :TASKNAME,
  7246. :STARTDATE,
  7247. :ENDDATE,
  7248. :PROJECTNAME,
  7249. :TASKTYPE,
  7250. :MARKER,
  7251. :ACT_CNT,
  7252. :istasknew,
  7253. :isactnew,
  7254. :isreport,
  7255. :isreject
  7256. do
  7257. begin
  7258. Author = '';
  7259. Controller = '';
  7260. Responsible = '';
  7261. Worker = '';
  7262. for
  7263. select
  7264. gt.IS_AUTHOR,
  7265. gt.IS_CONTROLER,
  7266. gt.IS_RESPPERSON,
  7267. gt.IS_WORKER,
  7268. e.NAME
  7269. from
  7270. GROUPTASK gt
  7271. join EMPLOYER e on
  7272. e.ID = gt.ID_EMPLOYER
  7273. where
  7274. gt.ID_TASK = :TASKID
  7275. into
  7276. :is_author,
  7277. :is_controller,
  7278. :is_responsible,
  7279. :is_worker,
  7280. :emp_name
  7281. do
  7282. begin
  7283. if (is_author = 1) then
  7284. begin
  7285. if (Author <> '') then Author = Author || ',';
  7286. Author = Author || emp_name;
  7287. end
  7288.  
  7289. if (is_controller = 1) then
  7290. begin
  7291. if (Controller <> '') then Controller = Controller || ',';
  7292. Controller = Controller || emp_name;
  7293. end
  7294.  
  7295. if (is_responsible = 1) then
  7296. begin
  7297. if (Responsible <> '') then Responsible = Responsible || ',';
  7298. Responsible = Responsible || emp_name;
  7299. end
  7300.  
  7301. if (is_worker = 1) then
  7302. begin
  7303. if (Worker <> '') then Worker = Worker || ',';
  7304. Worker = Worker || emp_name;
  7305. end
  7306. end
  7307.  
  7308. if ( ( (ACT_CNT=0)or(ACT_CNT is null) ) ) then isactnew = 0;
  7309. if (isreject is null) then isreject = 0;
  7310. taskstate = istasknew || isactnew || isreport || isreject;
  7311.  
  7312. SUSPEND;
  7313. end
  7314. END
  7315. ^
  7316.  
  7317. SET TERM ; ^
  7318.  
  7319. SET TERM ^ ;
  7320. CREATE OR ALTER PROCEDURE CLOSE_TASK_WITH_RESOLUTION (
  7321. i_id_task integer)
  7322. as
  7323. declare variable l_subtask_id integer;
  7324. begin
  7325. update task set state=1 where id=:i_id_task;
  7326. for select t.id
  7327. from task t
  7328. where t.parentid=:i_id_task and t.isdeleted=0 and t.state=0
  7329. into :l_subtask_id
  7330. do
  7331. execute procedure CLOSE_TASK_WITH_RESOLUTION(:l_subtask_id);
  7332. end
  7333. ^
  7334. SET TERM ; ^
  7335. GRANT SELECT,UPDATE ON TASK TO PROCEDURE CLOSE_TASK_WITH_RESOLUTION;
  7336. GRANT EXECUTE ON PROCEDURE CLOSE_TASK_WITH_RESOLUTION TO PROCEDURE CLOSE_TASK_WITH_RESOLUTION;
  7337. GRANT EXECUTE ON PROCEDURE CLOSE_TASK_WITH_RESOLUTION TO SYSDBA;
  7338. SET TERM ^ ;
  7339. CREATE OR ALTER PROCEDURE TMP_EDITMENU4IAP
  7340. as
  7341. declare variable v_max_num smallint;
  7342. declare variable v_max_item_id integer;
  7343. declare variable v_id integer;
  7344. declare variable v_url varchar(200) character set win1251;
  7345. declare variable v_isvisible smallint;
  7346. declare variable v_isdefvisible smallint;
  7347. declare variable v_id_employer integer;
  7348. declare variable v_old_num integer;
  7349. declare variable v_count integer;
  7350. begin
  7351. if (not exists (select first (1) id from menuitems where dmess_tagname = 'L_MENU_IAP_TASKS')) then
  7352. begin
  7353.  
  7354. select
  7355. max(number),
  7356. max(item_id)
  7357. from
  7358. menuitems
  7359. into
  7360. :v_max_num,
  7361. :v_max_item_id;
  7362.  
  7363. v_max_num = v_max_num + 1;
  7364. v_max_item_id = v_max_item_id + 1;
  7365.  
  7366. for
  7367. select
  7368. id,
  7369. url,
  7370. isvisible,
  7371. isdefvisible,
  7372. id_employer
  7373. from
  7374. menuitems
  7375. where
  7376. dmess_tagname = 'L_MENU_IAP'
  7377. into
  7378. :v_id,
  7379. :v_url,
  7380. :v_isvisible,
  7381. :v_isdefvisible,
  7382. :v_id_employer
  7383. do
  7384. begin
  7385. select first (1)
  7386. number
  7387. from
  7388. menuitems
  7389. where
  7390. dmess_tagname = 'L_MENU_TABLE_TYPES' and
  7391. id_employer = :v_id_employer
  7392. into
  7393. :v_old_num;
  7394.  
  7395. insert into menuitems (
  7396. item_id,
  7397. idparent,
  7398. dmess_tagname,
  7399. url,
  7400. number,
  7401. isvisible,
  7402. isdefvisible,
  7403. right_kind,
  7404. id_employer
  7405. ) values (
  7406. :v_max_item_id,
  7407. :v_id,
  7408. 'L_MENU_IAP_TASKS',
  7409. :v_url,
  7410. :v_old_num,
  7411. :v_isvisible,
  7412. :v_isdefvisible,
  7413. 0,
  7414. :v_id_employer
  7415. );
  7416.  
  7417. update
  7418. menuitems
  7419. set
  7420. idparent = :v_id,
  7421. right_kind = 0,
  7422. number = :v_max_num,
  7423. url = null
  7424. where
  7425. dmess_tagname = 'L_MENU_TABLE_TYPES' and
  7426. id_employer = :v_id_employer;
  7427. end
  7428.  
  7429. update menuitems set url = null, right_kind = 0 where dmess_tagname = 'L_MENU_IAP';
  7430. end
  7431. end^
  7432. SET TERM ; ^
  7433. GRANT SELECT,INSERT,UPDATE ON MENUITEMS TO PROCEDURE TMP_EDITMENU4IAP;
  7434. GRANT EXECUTE ON PROCEDURE TMP_EDITMENU4IAP TO SYSDBA;
  7435.  
  7436. EXECUTE PROCEDURE TMP_EDITMENU4IAP;
  7437. commit;
  7438. DROP PROCEDURE TMP_EDITMENU4IAP;
  7439. commit;
  7440. EXECUTE PROCEDURE ADD_INDEX_IF_DOES_NOT_EXIST('TASK_IDX_NREC_TASKTYPE', 'TASK', 'NRECORD_TASKTYPE');
  7441.  
  7442. RESULT
  7443. =======
  7444. 0
  7445.  
  7446. commit;
  7447.  
  7448. SET TERM ^ ;
  7449. CREATE OR ALTER PROCEDURE TMP_DROP_XLAM
  7450. AS
  7451. declare variable is_exist smallint;
  7452. BEGIN
  7453. SELECT result FROM IS_PROCEDURE_EXISTS('GETDOCUMENTS_ARCHIVE_COUNT')
  7454. INTO :is_exist;
  7455.  
  7456. IF (is_exist = 1) THEN
  7457. begin
  7458. EXECUTE STATEMENT
  7459. 'DROP PROCEDURE GETDOCUMENTS_ARCHIVE_COUNT;';
  7460. end
  7461.  
  7462. SELECT result FROM IS_PROCEDURE_EXISTS('GETDOCUMENTS_FORSEARCH_COUNT')
  7463. INTO :is_exist;
  7464.  
  7465. IF (is_exist = 1) THEN
  7466. begin
  7467. EXECUTE STATEMENT
  7468. 'DROP PROCEDURE GETDOCUMENTS_FORSEARCH_COUNT;';
  7469. end
  7470.  
  7471. SELECT result FROM IS_PROCEDURE_EXISTS('GETDOCUMENTS_FORSEARCH_ALL')
  7472. INTO :is_exist;
  7473.  
  7474. IF (is_exist = 1) THEN
  7475. begin
  7476. EXECUTE STATEMENT
  7477. 'DROP PROCEDURE GETDOCUMENTS_FORSEARCH_ALL;';
  7478. end
  7479.  
  7480. SELECT result FROM IS_FIELD_EXISTS('EMPLOYER', 'ISSHOWTOTALPAGES')
  7481. INTO :is_exist;
  7482.  
  7483. IF (is_exist = 1) THEN
  7484. begin
  7485. EXECUTE STATEMENT
  7486. 'ALTER TABLE EMPLOYER DROP ISSHOWTOTALPAGES;';
  7487. end
  7488. END ^
  7489. SET TERM ; ^
  7490. commit;
  7491.  
  7492. EXECUTE PROCEDURE TMP_DROP_XLAM;
  7493. commit;
  7494. DROP PROCEDURE TMP_DROP_XLAM;
  7495. commit;
  7496.  
  7497.  
  7498. /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  7499. /* 05.07.2010 Elena, Поиск документов
  7500. Вот условия, по которым определяется доступ к документам для всех участников:
  7501. 1. Автору документа.
  7502. 2. Пользователю, имеющему полномочия «Полные права» на автора документа.
  7503. 3. Контролеру типа документа, имеющему полномочия «Только свои задачи» или «Полные права» на автора документа.
  7504. 4. Любому участнику задачи по рассмотрению/исполнению документа.
  7505. 5. Контролеру типа документа, имеющему полномочия «Только свои задачи» или «Полные права» на участника задачи по рассмотрению или исполнению документа.
  7506. /*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  7507. SET TERM ^ ;
  7508.  
  7509. CREATE OR ALTER PROCEDURE GETDOCUMENTS_FORSEARCH_FAST (
  7510. i_id_employer integer,
  7511. i_id_doctype integer,
  7512. i_doc_version integer)
  7513. returns (
  7514. o_id_document integer)
  7515. as
  7516. declare variable l_isController smallint;
  7517. begin
  7518. select cdtr.o_result
  7519. from CHECKDOCTYPERIGHT(:i_id_doctype, :i_id_employer, 1) cdtr
  7520. into :l_isController;
  7521.  
  7522. if (l_isController = 0) then
  7523. begin
  7524. /* 1. Автору документа.
  7525. 2. Пользователю, имеющему полномочия «Полные права» на автора документа. */
  7526. for select distinct d.id
  7527. from documents d
  7528. inner join GETPERM_ALL(:i_id_employer) gp on (gp.o_id = d.id_author and gp.o_right = 1)
  7529. where d.id_doctype = :i_id_doctype and
  7530. d.doc_version = :i_doc_version and
  7531. d.isdeleted = 0
  7532. into :o_id_document
  7533. do
  7534. suspend;
  7535.  
  7536. /* 4. Любому участнику задачи по рассмотрению/исполнению документа. */
  7537. for select distinct d.id
  7538. from documents d
  7539. left join task t on (t.id_document_exec = d.id or t.id_document = d.id)
  7540. left join grouptask gt on (gt.id_task = t.id)
  7541. where d.isdeleted = 0 and
  7542. d.id_doctype = :i_id_doctype and
  7543. d.doc_version = :i_doc_version and
  7544. gt.id_employer = :i_id_employer
  7545. into :o_id_document
  7546. do
  7547. suspend;
  7548. end
  7549. else
  7550. begin
  7551. /* 1. Автору документа.
  7552. 2. Пользователю, имеющему полномочия «Полные права» на автора документа.
  7553. 3. Контролеру типа документа, имеющему полномочия «Только свои задачи» или «Полные права» на автора документа. */
  7554. for select distinct d.id
  7555. from documents d
  7556. inner join GETPERM_ALL(:i_id_employer) gp on (gp.o_id = d.id_author)
  7557. where d.id_doctype = :i_id_doctype and
  7558. d.doc_version = :i_doc_version and
  7559. d.isdeleted = 0
  7560. into :o_id_document
  7561. do
  7562. suspend;
  7563.  
  7564. /* 4. Любому участнику задачи по рассмотрению/исполнению документа.
  7565. 5. Контролеру типа документа, имеющему полномочия «Только свои задачи» или «Полные права» на участника задачи по рассмотрению или исполнению документа. */
  7566. for select distinct d.id
  7567. from documents d
  7568. left join task t on (t.id_document_exec = d.id or t.id_document = d.id)
  7569. left join grouptask gt on (gt.id_task = t.id)
  7570. inner join GETPERM_ALL(:i_id_employer) gp on (gp.o_id = gt.id_employer)
  7571. where d.isdeleted = 0 and
  7572. d.id_doctype = :i_id_doctype and
  7573. d.doc_version = :i_doc_version
  7574. into :o_id_document
  7575. do
  7576. suspend;
  7577. end
  7578. end^
  7579.  
  7580. SET TERM ; ^
  7581. commit;
  7582.  
  7583. /* добавляем признак "Секретная задача" в шаблоны задач */
  7584. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('TASK_TEMPLATES', 'ISSECRET', 'SMALLINT');
  7585.  
  7586. RESULT
  7587. =======
  7588. 0
  7589.  
  7590. commit;
  7591.  
  7592.  
  7593. SET TERM ^ ;
  7594.  
  7595. ALTER PROCEDURE SIGNDOCUMENT_PASSING_POINT (
  7596. i_routetreeid integer)
  7597. returns (
  7598. o_routetreeid integer,
  7599. o_inarchive integer)
  7600. as
  7601. declare variable l_parentid integer;
  7602. declare variable l_is_do_it smallint;
  7603. declare variable l_x integer;
  7604. declare variable l_y integer;
  7605. declare variable l_taskid integer;
  7606. declare variable l_isvirtual smallint;
  7607. declare variable l_documentid integer;
  7608. declare variable l_stage smallint;
  7609. declare variable k smallint;
  7610. declare variable is_virt smallint;
  7611. declare variable idc integer;
  7612. declare variable idc1 integer;
  7613. declare variable x integer;
  7614. declare variable y integer;
  7615. declare variable l_h integer;
  7616. declare variable is_exit smallint;
  7617. begin
  7618. O_ROUTETREEID = null;
  7619. O_INARCHIVE = 0;
  7620. select
  7621. id_parent, is_do_it, x, y, id_task,
  7622. isvirtual, id_document, stage
  7623. from
  7624. routetrees
  7625. where
  7626. id = :i_routetreeid
  7627. into
  7628. :l_parentid, :l_is_do_it, :l_x, :l_y, :l_taskid,
  7629. :l_isvirtual, :l_documentid, :l_stage;
  7630.  
  7631. /* Устанавливаем is_do_it в 1 у всех совпадающих X Y */
  7632. update routetrees
  7633. set is_do_it = 1
  7634. where
  7635. X = :l_x and
  7636. Y = :l_y and
  7637. ID_DOCUMENT = :l_documentid and
  7638. stage = :l_stage and
  7639. isdeleted = 0;
  7640.  
  7641. /* Проверяем все ли отделы согласовали */
  7642. if (not exists( select
  7643. id
  7644. from
  7645. RouteTrees
  7646. where
  7647. ( IsVirtual = 0 or
  7648. IsVirtual = 2 or
  7649. IsVirtual = 4 or
  7650. IsVirtual = 5 or
  7651. IsVirtual = 6 or
  7652. IsVirtual = 8 or
  7653. IsVirtual = 9 or
  7654. IsVirtual = 10 or
  7655. IsVirtual = 11
  7656. ) and
  7657. ID_Document = :l_documentid and
  7658. IS_DO_IT = 0 and
  7659. stage = :l_stage and
  7660. IsDeleted = 0 and
  7661. ( is_exclude is null or
  7662. is_exclude=0
  7663. )
  7664. )
  7665. )
  7666. then begin
  7667. if (exists( select id
  7668. from routetrees
  7669. where
  7670. ID_Document = :l_documentid and
  7671. stage = :l_stage and
  7672. IsVirtual = 7 and
  7673. isdeleted = 0 and
  7674. ( is_exclude is null or
  7675. is_exclude = 0
  7676. )
  7677. )
  7678. )
  7679. then
  7680. begin
  7681. k = 4;
  7682. O_INARCHIVE = 1;
  7683. end
  7684. else
  7685. k = 1;
  7686.  
  7687. update Documents
  7688. set State = :k
  7689. where ID = :l_documentid;
  7690.  
  7691. update Task
  7692. set State = 1
  7693. where ID = :l_taskid;
  7694.  
  7695. delete from favdocument
  7696. where id_document = :l_documentid;
  7697.  
  7698. suspend;
  7699. exit;
  7700. end
  7701.  
  7702.  
  7703. if (l_isvirtual = 1) then
  7704. begin
  7705. is_exit = 0;
  7706. for
  7707. select O_RESULT, O_ROUTETREEID
  7708. from sign_where_isvirtual_1(:i_routetreeid, :L_DOCUMENTID, :L_STAGE)
  7709. into :L_H, :O_ROUTETREEID
  7710. do
  7711. if (L_H = 1) then
  7712. begin
  7713. is_exit = 1;
  7714. suspend;
  7715. end
  7716.  
  7717. if (is_exit = 1) then exit;
  7718. end
  7719.  
  7720.  
  7721. /* Цикл по всем предкам Если у них есть задачи и он закрытые,
  7722. * то эту тоже закрываем */
  7723. execute procedure signdocument_is_all_parent_sign(:i_routetreeid, 1)
  7724. returning_values :L_H;
  7725.  
  7726. if (L_H = 1) then
  7727. begin
  7728. /* Закрываем задачу */
  7729. update Task
  7730. set State = 1
  7731. where ID = :L_TASKID;
  7732.  
  7733. /* Цикл по всем потомкам */
  7734. k = 0;
  7735. for
  7736. select
  7737. id, x, y, isvirtual
  7738. from
  7739. RouteTrees
  7740. where
  7741. ID_Parent = :i_routetreeid and
  7742. ID_Document = :l_documentid and
  7743. stage = :l_stage and
  7744. IsDeleted = 0 and
  7745. :K = 0
  7746. into
  7747. :IDC, :X, :Y, :IS_VIRT
  7748. do
  7749. begin
  7750. execute procedure signdocument_is_all_parent_sign(:IDC ,0)
  7751. returning_values :L_H;
  7752.  
  7753. if (L_H = 0) then exit;
  7754. end
  7755.  
  7756.  
  7757. if (IS_VIRT = 1) then
  7758. begin
  7759. for
  7760. select
  7761. x, y
  7762. from
  7763. RouteTrees
  7764. where
  7765. ID_Parent = :i_routetreeid and
  7766. ID_Document = :l_documentid and
  7767. stage = :l_stage and
  7768. isvirtual = 1 and
  7769. IsDeleted = 0
  7770. into
  7771. :X, :Y
  7772. do
  7773. begin
  7774. for
  7775. select
  7776. id
  7777. from
  7778. routetrees
  7779. where
  7780. ID_Document = :l_documentid and
  7781. stage = :l_stage and
  7782. isdeleted = 0 and
  7783. x = :X and
  7784. y = :Y
  7785. into
  7786. :IDC
  7787. do
  7788. if (exists( select
  7789. id
  7790. from
  7791. routetrees
  7792. where
  7793. ID_Document = :l_documentid and
  7794. stage = :l_stage and
  7795. isdeleted = 0 and
  7796. id_parent = :IDC
  7797. )
  7798. )
  7799. then
  7800. begin
  7801. for
  7802. select o_routetreeid
  7803. from signdocument_passing_point(:IDC)
  7804. into :o_routetreeid
  7805. do
  7806. suspend;
  7807. end
  7808. end
  7809. exit;
  7810. end
  7811.  
  7812.  
  7813. for
  7814. select
  7815. id, x, y
  7816. from
  7817. RouteTrees
  7818. where
  7819. ID_Parent = :i_routetreeid and
  7820. ID_Document = :l_documentid and
  7821. stage = :l_stage and
  7822. IsDeleted = 0
  7823. into
  7824. :IDC, :X, :Y
  7825. do
  7826. begin
  7827. IDC1 = null;
  7828.  
  7829. select
  7830. min(rt.id_parent)
  7831. from
  7832. routetrees rt,
  7833. routenode rn
  7834. where
  7835. ID_Document = :l_documentid and
  7836. rt.stage = :l_stage and
  7837. rt.isdeleted = 0 and
  7838. rt.x = :X and
  7839. rt.y = :Y and
  7840. ( rn.id_routetree = rt.id or
  7841. rt.isvirtual = 1
  7842. )
  7843. into
  7844. :IDC1;
  7845.  
  7846. if (IDC1 is not null) then
  7847. begin
  7848. O_ROUTETREEID = IDC1;
  7849. suspend;
  7850. exit;
  7851. end
  7852. end
  7853. end
  7854.  
  7855. if ( exists(select first 1 rt.id
  7856. from routetrees rt
  7857. join routenode rn on (rt.id = rn.id_routetree)
  7858. where (rt.isdeleted = 0) and (rn.isdeleted = 0) and (rt.id_task = :l_taskid)
  7859. and (rn.is_do_it = 0) and (rn.necessary = 1) and (rt.id_parent = :l_parentid)))
  7860. then exit;
  7861.  
  7862. O_ROUTETREEID = :i_routetreeid;
  7863. suspend;
  7864. end
  7865. ^
  7866.  
  7867. SET TERM ; ^
  7868. commit;
  7869.  
  7870. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('MENUITEMS', 'EDITION', 'VARCHAR(10)');
  7871.  
  7872. RESULT
  7873. =======
  7874. 0
  7875.  
  7876. commit;
  7877.  
  7878. SET TERM ^ ;
  7879.  
  7880. CREATE OR ALTER PROCEDURE ADDNEWMENUITEM (
  7881. i_item_id integer,
  7882. i_dmess_tagname varchar(200),
  7883. i_url varchar(1000),
  7884. i_parent_number integer,
  7885. i_number smallint,
  7886. i_isdefvisible smallint,
  7887. i_right_kind smallint,
  7888. i_edition varchar(10))
  7889. as
  7890. declare variable l_id_employer integer;
  7891. declare variable l_idparent integer;
  7892. begin
  7893. /*Описание: Эта процедура добавляет новые пункты в меню.
  7894. Параметры:
  7895. i_item_id - номер, ассоциированный с пунктом меню (для групповых элементов равен null)
  7896. i_dmesstagname - тэг из dmessages.xml, которым называется данный пункт меню
  7897. i_url - ссылка (для групповых элементов не нужна)
  7898. i_parent_number - порядковый номер родительского элемента (или 0, если родителя нет)
  7899. i_number - порядковый номер элемента
  7900. i_isdefvisible - виден ли добавляемый элемент по умолчанию у новых пользователей (0 или 1)
  7901. i_right_kind - кто может видеть данный пункт (см. описание поля right_kind в таблице menuitems)
  7902. i_edition - версия (workflow/docflow) null - видим для всех версий лицензий
  7903. Например:
  7904. 1. Добавить новый 3-й по счету пункт во вторую группу меню:
  7905. execute procedure addnewmenuitem(676,'L_GLOBAL_PROJECT','/user/mytasks/',2,3,1,0,'workflow');
  7906. 2. Добавить новую группу меню:
  7907. execute procedure addnewmenuitem(null,'L_GLOBAL_PROJECT',null,0,3,1,0,null);
  7908. */
  7909. /*добавляем пункт меню в админскую настройку*/
  7910. l_idparent = null;
  7911. if (i_parent_number = 0) then
  7912. l_idparent = 0;
  7913. else
  7914. select id from menuitems m where m.idparent=0 and m.id_employer=0 and m.number=:i_parent_number
  7915. into :l_idparent;
  7916. /*Если был указан неправильный i_parent_number, то ничего не добавляем*/
  7917. if (l_idparent is null) then
  7918. exit;
  7919. /* Проверяем, существует ли уже пункт меню с таким же i_item_id. Если существует, то ничего не делаем. */
  7920. if (exists(select id
  7921. from menuitems
  7922. where item_id=:i_item_id)) then exit;
  7923. if (exists(select id
  7924. from menuitems
  7925. where dmess_tagname=:i_dmess_tagname and url is null)) then exit;
  7926. update menuitems m
  7927. set m.number = m.number + 1
  7928. where m.id_employer=0 and m.idparent=:l_idparent and m.number>=:i_number;
  7929. /*для id_employer = -1 неверно значение :l_idparent. Нужен дополнительный запрос*/
  7930. insert into menuitems (item_id,dmess_tagname,url,idparent,number,
  7931. isdefvisible,right_kind,id_employer,edition)
  7932. values (:i_item_id, :i_dmess_tagname, :i_url, :l_idparent, :i_number,
  7933. :i_isdefvisible, :i_right_kind, -1, :i_edition);
  7934.  
  7935. insert into menuitems (item_id,dmess_tagname,url,idparent,number,
  7936. isdefvisible,right_kind,id_employer,edition)
  7937. values (:i_item_id, :i_dmess_tagname, :i_url, :l_idparent, :i_number,
  7938. :i_isdefvisible, :i_right_kind, 0, :i_edition);
  7939.  
  7940. /*добавляем пункт меню в настройки пользователей*/
  7941. for select e.id from employer e
  7942. where e.isdeleted=0 and e.parentid is null and
  7943. (exists (select first 1 m.id from menuitems m where m.id_employer=e.id))
  7944. into :l_id_employer
  7945. do
  7946. begin
  7947. if (i_parent_number = 0) then
  7948. l_idparent = 0;
  7949. else
  7950. select id from menuitems m
  7951. where m.idparent=0 and m.id_employer=:l_id_employer and m.number=:i_parent_number
  7952. into :l_idparent;
  7953.  
  7954. update menuitems m
  7955. set m.number = m.number + 1
  7956. where m.id_employer=:l_id_employer and m.idparent=:l_idparent and m.number>=:i_number;
  7957. insert into menuitems (item_id,dmess_tagname,url,idparent,number,
  7958. right_kind,id_employer,edition)
  7959. values (:i_item_id, :i_dmess_tagname, :i_url, :l_idparent, :i_number,
  7960. :i_right_kind, :l_id_employer, :i_edition);
  7961. end
  7962. end^
  7963.  
  7964. SET TERM ; ^
  7965.  
  7966. COMMENT ON PROCEDURE ADDNEWMENUITEM IS
  7967. 'Описание: Эта процедура добавляет новые пункты в меню.
  7968. Параметры:
  7969. i_item_id - номер, ассоциированный с пунктом меню (для групповых элементов равен null)
  7970. i_dmesstagname - тэг из dmessages.xml, которым называется данный пункт меню
  7971. i_url - ссылка (для групповых элементов не нужна)
  7972. i_parent_number - порядковый номер родительского элемента (или 0, если родителя нет)
  7973. i_number - порядковый номер элемента
  7974. i_isdefvisible - виден ли добавляемый элемент по умолчанию у новых пользователей (0 или 1)
  7975. i_right_kind - кто может видеть данный пункт (см. описание поля right_kind в таблице menuitems)
  7976. i_edition - версия (workflow/docflow) null - видим для всех версий лицензий
  7977.  
  7978. Например:
  7979. 1. Добавить новый 3-й по счету пункт во вторую группу меню:
  7980. execute procedure addnewmenuitem(676,''L_GLOBAL_PROJECT'',''/user/mytasks/'',2,3,1,0,''workflow'');
  7981. 2. Добавить новую группу меню:
  7982. execute procedure addnewmenuitem(null,''L_GLOBAL_PROJECT'',null,0,3,1,0,null);';
  7983. commit;
  7984.  
  7985. /* Добавлено копирование признака "Версия" */
  7986. SET TERM ^ ;
  7987.  
  7988. CREATE OR ALTER PROCEDURE COPYMENUITEMS (
  7989. i_id_employer integer)
  7990. as
  7991. declare variable l_id integer;
  7992. declare variable l_item_id integer;
  7993. declare variable l_dmess_tagname varchar(200);
  7994. declare variable l_url varchar(1000);
  7995. declare variable l_number smallint;
  7996. declare variable l_isvisible smallint;
  7997. declare variable l_right_kind smallint;
  7998. declare variable l_edition varchar(10);
  7999. declare variable l_id2 integer;
  8000. declare variable l_item_id2 integer;
  8001. declare variable l_dmess_tagname2 varchar(200);
  8002. declare variable l_url2 varchar(1000);
  8003. declare variable l_number2 smallint;
  8004. declare variable l_isvisible2 smallint;
  8005. declare variable l_isdefvisible2 smallint;
  8006. declare variable l_right_kind2 smallint;
  8007. declare variable l_edition2 varchar(10);
  8008. declare variable l_id_new integer;
  8009. begin
  8010. for select
  8011. m.id, m.item_id, m.dmess_tagname, m.url, m.number,
  8012. m.isvisible, m.right_kind, m.edition
  8013. from menuitems m
  8014. where m.id_employer=0 and m.idparent=0
  8015. into :l_id,:l_item_id,:l_dmess_tagname,:l_url,:l_number,
  8016. :l_isvisible,:l_right_kind,:l_edition
  8017. do
  8018. begin
  8019. l_id_new = gen_id(gen_menuitems_id,1);
  8020. insert into menuitems (id,item_id,dmess_tagname,url,number,isvisible,right_kind,id_employer,edition)
  8021. values (:l_id_new,:l_item_id,:l_dmess_tagname,:l_url,:l_number,:l_isvisible,:l_right_kind,:i_id_employer,:l_edition);
  8022.  
  8023. for select
  8024. m.id, m.item_id, m.dmess_tagname, m.url, m.number,
  8025. m.isvisible, m.isdefvisible, m.right_kind, m.edition
  8026. from menuitems m
  8027. where m.id_employer=0 and m.idparent=:l_id
  8028. into :l_id2,:l_item_id2,:l_dmess_tagname2,:l_url2,:l_number2,
  8029. :l_isvisible2,:l_isdefvisible2,:l_right_kind2,:l_edition2
  8030. do
  8031. begin
  8032. insert into menuitems (item_id,dmess_tagname,url,number,isvisible,right_kind,idparent,id_employer,edition)
  8033. values (:l_item_id2,:l_dmess_tagname2,:l_url2,:l_number2,:l_isvisible2,:l_right_kind2,:l_id_new,:i_id_employer,:l_edition2);
  8034. end
  8035. end
  8036. end^
  8037.  
  8038. SET TERM ; ^
  8039. commit;
  8040.  
  8041. /*Заполняем поле "Версия" для пунктов меню */
  8042. /*
  8043. SET TERM ^ ;
  8044. CREATE OR ALTER PROCEDURE TMP_FILL_MENUITEMS_EDITION
  8045. AS
  8046. BEGIN
  8047. UPDATE
  8048. menuitems
  8049. SET
  8050. edition = 'docflow'
  8051. WHERE
  8052. dmess_tagname = 'L_MENU_DOCUMENTS' OR
  8053. dmess_tagname = 'L_DOCPROCESSING' OR
  8054. item_id IN (21, 22, 23, 24, 26, 29, 30, 33, 61, 86, 89, 118, 119, 121, 122, 140, 149, 666, 11100, 11836, 13666);
  8055. UPDATE
  8056. menuitems
  8057. SET
  8058. edition = 'workflow'
  8059. WHERE
  8060. item_id IN (66, 129, 11838);
  8061. END ^
  8062. SET TERM ; ^
  8063. commit;
  8064.  
  8065. EXECUTE PROCEDURE TMP_FILL_MENUITEMS_EDITION;
  8066. commit;
  8067. DROP PROCEDURE TMP_FILL_MENUITEMS_EDITION;
  8068. commit;
  8069. */
  8070. /* добавляем атрибут "Версия" для прав */
  8071. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('GROUPRIGHTS_LIST', 'EDITION', 'VARCHAR(10)');
  8072.  
  8073. RESULT
  8074. =======
  8075. 0
  8076.  
  8077. commit;
  8078.  
  8079. /*Заполняем поле "Версия" для прав */
  8080. SET TERM ^ ;
  8081. CREATE OR ALTER PROCEDURE TMP_FILL_RIGHTS_EDITION
  8082. AS
  8083. BEGIN
  8084. UPDATE
  8085. grouprights_list
  8086. SET
  8087. edition = 'docflow'
  8088. WHERE
  8089. id in (4, 11, 31, 32, 33);
  8090. END ^
  8091. SET TERM ; ^
  8092. commit;
  8093.  
  8094. EXECUTE PROCEDURE TMP_FILL_RIGHTS_EDITION;
  8095. commit;
  8096. DROP PROCEDURE TMP_FILL_RIGHTS_EDITION;
  8097. commit;
  8098.  
  8099. /* Выбор прав для workflow-версии (не возвращает права, используемые в документообороте) */
  8100. SET TERM ^ ;
  8101.  
  8102. CREATE OR ALTER PROCEDURE GET_RIGHTS_OF_GROUP_WORKFLOW (
  8103. i_id_employer integer,
  8104. i_id_groupright integer)
  8105. returns (
  8106. o_right_kind integer,
  8107. o_id_object integer,
  8108. o_objectname varchar(1000),
  8109. o_group_has_right smallint,
  8110. o_can_edit smallint)
  8111. as
  8112. declare variable l_id_owner integer;
  8113. declare variable l_id_groupright integer;
  8114. begin
  8115.  
  8116. O_ID_OBJECT = 0;
  8117. O_OBJECTNAME = '';
  8118. for select gl.id
  8119. from grouprights_list gl
  8120. where gl.edition = 'workflow' or gl.edition is null
  8121. into :O_RIGHT_KIND
  8122. do
  8123. begin
  8124. select o_result from get_right_employer_and_group(:i_id_employer,:o_right_kind,0)
  8125. into :o_can_edit;
  8126.  
  8127. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8128. into :o_group_has_right;
  8129. suspend;
  8130. end
  8131.  
  8132. o_right_kind = 12;
  8133. for select it.id, it.name, it.id_owner from iwgtemplate it
  8134. where it.isdeleted=0
  8135. into :o_id_object, :o_objectname, :l_id_owner
  8136. do
  8137. begin
  8138. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  8139. o_can_edit = 1;
  8140. else
  8141. o_can_edit = 0;
  8142. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8143. into :o_group_has_right;
  8144. suspend;
  8145. end
  8146.  
  8147. o_right_kind = 10;
  8148. if (I_ID_GROUPRIGHT is null) then L_ID_GROUPRIGHT=0;
  8149. else
  8150. L_ID_GROUPRIGHT=:I_ID_GROUPRIGHT;
  8151. for select g.id, g.name, g.id_owner from grouprights g
  8152. where g.isdeleted=0 and g.isvisible=1 and g.id<>:L_ID_GROUPRIGHT
  8153. into :o_id_object, :o_objectname, :l_id_owner
  8154. do
  8155. begin
  8156. if (l_id_owner=i_id_employer ) then
  8157. o_can_edit = 1;
  8158. else
  8159. o_can_edit = 0;
  8160. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8161. into :o_group_has_right;
  8162. suspend;
  8163. end
  8164. o_right_kind = 15;
  8165. o_can_edit = 1;
  8166. for select md.id, md.name, md.id_owner
  8167. from meta_dictionary md
  8168. where md.isdeleted=0 and md.id_owner=:i_id_employer and recordtype=1
  8169. into :o_id_object, :o_objectname, :l_id_owner
  8170. do
  8171. begin
  8172. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8173. into :o_group_has_right;
  8174. suspend;
  8175. end
  8176. /* 17 права на просмотр записей в справочнике */
  8177. /* 18 права на добавление записей в справочник */
  8178. /* 19 права на изменение записей в справочнике */
  8179. /* 20 права на удаление записей в справочнике */
  8180. o_can_edit = 1;
  8181. for select md.id, md.name, md.id_owner
  8182. from meta_dictionary md
  8183. where md.isdeleted=0 and md.id_owner=:i_id_employer and recordtype=0
  8184. into :o_id_object, :o_objectname, :l_id_owner
  8185. do
  8186. begin
  8187. o_right_kind = 17;
  8188. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8189. into :o_group_has_right;
  8190. suspend;
  8191. o_right_kind = 18;
  8192. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8193. into :o_group_has_right;
  8194. suspend;
  8195. o_right_kind = 19;
  8196. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8197. into :o_group_has_right;
  8198. suspend;
  8199. o_right_kind = 20;
  8200. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8201. into :o_group_has_right;
  8202. suspend;
  8203. end
  8204. o_right_kind = 22;
  8205. for select tt.id, tt.name, tt.id_owner from task_templates tt
  8206. into :o_id_object, :o_objectname, :l_id_owner
  8207. do
  8208. begin
  8209. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  8210. o_can_edit = 1;
  8211. else
  8212. o_can_edit = 0;
  8213. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8214. into :o_group_has_right;
  8215. suspend;
  8216. end
  8217. -- плагины не привязвнные к типам
  8218. o_right_kind = 77;
  8219. for select plg.id, plg.name, plg.id_owner from plugins plg where plg.no_connect_to_type=1
  8220. into :o_id_object, :o_objectname, :l_id_owner
  8221. do
  8222. begin
  8223. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  8224. o_can_edit = 1;
  8225. else
  8226. o_can_edit = 0;
  8227. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8228. into :o_group_has_right;
  8229. suspend;
  8230. end
  8231. /* 23 права на просмотр событий календаря */
  8232. /* 24 права на добавление и редактирование событий в календарь */
  8233. /* 25 полные права*/
  8234. o_can_edit = 1;
  8235. for select c.id, c.name, c.id_owner
  8236. from calendars c
  8237. where c.id_owner=:i_id_employer and is_system=0
  8238. into :o_id_object, :o_objectname, :l_id_owner
  8239. do
  8240. begin
  8241. o_right_kind = 23;
  8242. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8243. into :o_group_has_right;
  8244. suspend;
  8245. o_right_kind = 24;
  8246. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8247. into :o_group_has_right;
  8248. suspend;
  8249. o_right_kind = 25;
  8250. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8251. into :o_group_has_right;
  8252. suspend;
  8253. end
  8254. o_right_kind = 26;
  8255. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,0)
  8256. into :o_group_has_right;
  8257. suspend;
  8258.  
  8259. /* 27 права на общедоступные группы внешних пользователей */
  8260. for select eeg.id, eeg.name, eeg.id_owner from email_employer_group eeg
  8261. where eeg.isdeleted=0 and eeg.iscommon=1
  8262. into :o_id_object, :o_objectname, :l_id_owner
  8263. do
  8264. begin
  8265. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  8266. o_can_edit = 1;
  8267. else
  8268. o_can_edit = 0;
  8269. o_right_kind = 27;
  8270. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8271. into :o_group_has_right;
  8272. suspend;
  8273. end
  8274. end^
  8275.  
  8276. SET TERM ; ^
  8277. commit;
  8278.  
  8279. EXECUTE PROCEDURE GIVE_GRANTS_TO_ALL('PROCEDURE','GET_RIGHTS_OF_GROUP_WORKFLOW','EXECUTE');
  8280. commit;
  8281.  
  8282. SET TERM ^ ;
  8283.  
  8284. CREATE OR ALTER PROCEDURE GET_RIGHTS_OF_EMPLOYER_WORKFLOW (
  8285. i_id_employer integer,
  8286. i_id_viewed_empl integer,
  8287. i_isusepersonalgroup smallint)
  8288. returns (
  8289. o_right_kind integer,
  8290. o_id_object integer,
  8291. o_objectname varchar(1000),
  8292. o_id_groupright integer,
  8293. o_groupright_name varchar(1000))
  8294. as
  8295. begin
  8296. for select gr.id,gr.name from grouprights_employer gre
  8297. left join grouprights gr on gr.id = gre.id_groupright
  8298. where gre.id_employer = :i_id_viewed_empl and gr.isdeleted=0 and
  8299. (gr.isvisible=1 or (:i_isusepersonalgroup=1)and(gr.isvisible=0))
  8300. into :o_id_groupright,:o_groupright_name
  8301. do
  8302. begin
  8303. for select grg.o_right_kind,grg.o_id_object,grg.o_objectname
  8304. from get_rights_of_group_workflow(:i_id_employer,:o_id_groupright) grg
  8305. where grg.o_group_has_right=1
  8306. into :o_right_kind, :o_id_object, :o_objectname
  8307. do
  8308. suspend;
  8309. end
  8310. end^
  8311.  
  8312. SET TERM ; ^
  8313. commit;
  8314.  
  8315. EXECUTE PROCEDURE GIVE_GRANTS_TO_ALL('PROCEDURE','GET_RIGHTS_OF_EMPLOYER_WORKFLOW','EXECUTE');
  8316. commit;
  8317.  
  8318. /* Выбор прав для docflow-версии (не возвращает права для задач) */
  8319. SET TERM ^ ;
  8320.  
  8321. CREATE OR ALTER PROCEDURE GET_RIGHTS_OF_GROUP_DOCFLOW (
  8322. i_id_employer integer,
  8323. i_id_groupright integer)
  8324. returns (
  8325. o_right_kind integer,
  8326. o_id_object integer,
  8327. o_objectname varchar(1000),
  8328. o_group_has_right smallint,
  8329. o_can_edit smallint)
  8330. as
  8331. declare variable l_id_owner integer;
  8332. declare variable l_id_groupright integer;
  8333. begin
  8334.  
  8335. O_ID_OBJECT = 0;
  8336. O_OBJECTNAME = '';
  8337. for select gl.id
  8338. from grouprights_list gl
  8339. where gl.edition = 'docflow' or gl.edition is null
  8340. into :O_RIGHT_KIND
  8341. do
  8342. begin
  8343. select o_result from get_right_employer_and_group(:i_id_employer,:o_right_kind,0)
  8344. into :o_can_edit;
  8345.  
  8346. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8347. into :o_group_has_right;
  8348. suspend;
  8349. end
  8350.  
  8351. for select dt.id, dt.name, dt.id_owner from doctypes dt
  8352. where dt.isdeleted=0
  8353. into :o_id_object, :o_objectname, :l_id_owner
  8354. do
  8355. begin
  8356. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  8357. o_can_edit = 1;
  8358. else
  8359. o_can_edit = 0;
  8360. o_right_kind = 1;
  8361. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8362. into :o_group_has_right;
  8363. suspend;
  8364. o_right_kind = 2;
  8365. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8366. into :o_group_has_right;
  8367. suspend;
  8368. o_right_kind = 28; /* 28 - право выбора связанных документов */
  8369. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8370. into :o_group_has_right;
  8371. suspend;
  8372. end
  8373.  
  8374. o_right_kind = 3;
  8375. for select rt.id, rt.name, rt.id_owner from routetemplate rt
  8376. where rt.isdeleted=0 and rt.kind=0
  8377. into :o_id_object, :o_objectname, :l_id_owner
  8378. do
  8379. begin
  8380. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  8381. o_can_edit = 1;
  8382. else
  8383. o_can_edit = 0;
  8384. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8385. into :o_group_has_right;
  8386. suspend;
  8387. end
  8388.  
  8389. o_right_kind = 9;
  8390. for select fd.id, fd.name, fd.id_owner from fdoctemplate fd
  8391. where fd.isdeleted=0
  8392. into :o_id_object, :o_objectname, :l_id_owner
  8393. do
  8394. begin
  8395. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  8396. o_can_edit = 1;
  8397. else
  8398. o_can_edit = 0;
  8399. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8400. into :o_group_has_right;
  8401. suspend;
  8402. end
  8403.  
  8404. o_right_kind = 10;
  8405. if (I_ID_GROUPRIGHT is null) then L_ID_GROUPRIGHT=0;
  8406. else
  8407. L_ID_GROUPRIGHT=:I_ID_GROUPRIGHT;
  8408. for select g.id, g.name, g.id_owner from grouprights g
  8409. where g.isdeleted=0 and g.isvisible=1 and g.id<>:L_ID_GROUPRIGHT
  8410. into :o_id_object, :o_objectname, :l_id_owner
  8411. do
  8412. begin
  8413. if (l_id_owner=i_id_employer ) then
  8414. o_can_edit = 1;
  8415. else
  8416. o_can_edit = 0;
  8417. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8418. into :o_group_has_right;
  8419. suspend;
  8420. end
  8421. o_right_kind = 15;
  8422. o_can_edit = 1;
  8423. for select md.id, md.name, md.id_owner
  8424. from meta_dictionary md
  8425. where md.isdeleted=0 and md.id_owner=:i_id_employer and recordtype=1
  8426. into :o_id_object, :o_objectname, :l_id_owner
  8427. do
  8428. begin
  8429. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8430. into :o_group_has_right;
  8431. suspend;
  8432. end
  8433. /* 17 права на просмотр записей в справочнике */
  8434. /* 18 права на добавление записей в справочник */
  8435. /* 19 права на изменение записей в справочнике */
  8436. /* 20 права на удаление записей в справочнике */
  8437. o_can_edit = 1;
  8438. for select md.id, md.name, md.id_owner
  8439. from meta_dictionary md
  8440. where md.isdeleted=0 and md.id_owner=:i_id_employer and recordtype=0
  8441. into :o_id_object, :o_objectname, :l_id_owner
  8442. do
  8443. begin
  8444. o_right_kind = 17;
  8445. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8446. into :o_group_has_right;
  8447. suspend;
  8448. o_right_kind = 18;
  8449. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8450. into :o_group_has_right;
  8451. suspend;
  8452. o_right_kind = 19;
  8453. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8454. into :o_group_has_right;
  8455. suspend;
  8456. o_right_kind = 20;
  8457. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8458. into :o_group_has_right;
  8459. suspend;
  8460. end
  8461. -- плагины не привязвнные к типам
  8462. o_right_kind = 77;
  8463. for select plg.id, plg.name, plg.id_owner from plugins plg where plg.no_connect_to_type=1
  8464. into :o_id_object, :o_objectname, :l_id_owner
  8465. do
  8466. begin
  8467. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  8468. o_can_edit = 1;
  8469. else
  8470. o_can_edit = 0;
  8471. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8472. into :o_group_has_right;
  8473. suspend;
  8474. end
  8475. /* 23 права на просмотр событий календаря */
  8476. /* 24 права на добавление и редактирование событий в календарь */
  8477. /* 25 полные права*/
  8478. o_can_edit = 1;
  8479. for select c.id, c.name, c.id_owner
  8480. from calendars c
  8481. where c.id_owner=:i_id_employer and is_system=0
  8482. into :o_id_object, :o_objectname, :l_id_owner
  8483. do
  8484. begin
  8485. o_right_kind = 23;
  8486. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8487. into :o_group_has_right;
  8488. suspend;
  8489. o_right_kind = 24;
  8490. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8491. into :o_group_has_right;
  8492. suspend;
  8493. o_right_kind = 25;
  8494. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8495. into :o_group_has_right;
  8496. suspend;
  8497. end
  8498. o_right_kind = 26;
  8499. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,0)
  8500. into :o_group_has_right;
  8501. suspend;
  8502.  
  8503. /* 27 права на общедоступные группы внешних пользователей */
  8504. for select eeg.id, eeg.name, eeg.id_owner from email_employer_group eeg
  8505. where eeg.isdeleted=0 and eeg.iscommon=1
  8506. into :o_id_object, :o_objectname, :l_id_owner
  8507. do
  8508. begin
  8509. if (l_id_owner=i_id_employer or l_id_owner is null ) then
  8510. o_can_edit = 1;
  8511. else
  8512. o_can_edit = 0;
  8513. o_right_kind = 27;
  8514. select o_result from get_right_groupright(:i_id_groupright,:o_right_kind,:o_id_object)
  8515. into :o_group_has_right;
  8516. suspend;
  8517. end
  8518. end^
  8519.  
  8520. SET TERM ; ^
  8521. commit;
  8522.  
  8523. EXECUTE PROCEDURE GIVE_GRANTS_TO_ALL('PROCEDURE','GET_RIGHTS_OF_GROUP_DOCFLOW','EXECUTE');
  8524. commit;
  8525.  
  8526. SET TERM ^ ;
  8527.  
  8528. CREATE OR ALTER PROCEDURE GET_RIGHTS_OF_EMPLOYER_DOCFLOW (
  8529. i_id_employer integer,
  8530. i_id_viewed_empl integer,
  8531. i_isusepersonalgroup smallint)
  8532. returns (
  8533. o_right_kind integer,
  8534. o_id_object integer,
  8535. o_objectname varchar(1000),
  8536. o_id_groupright integer,
  8537. o_groupright_name varchar(1000))
  8538. as
  8539. begin
  8540. for select gr.id,gr.name from grouprights_employer gre
  8541. left join grouprights gr on gr.id = gre.id_groupright
  8542. where gre.id_employer = :i_id_viewed_empl and gr.isdeleted=0 and
  8543. (gr.isvisible=1 or (:i_isusepersonalgroup=1)and(gr.isvisible=0))
  8544. into :o_id_groupright,:o_groupright_name
  8545. do
  8546. begin
  8547. for select grg.o_right_kind,grg.o_id_object,grg.o_objectname
  8548. from get_rights_of_group_docflow(:i_id_employer,:o_id_groupright) grg
  8549. where grg.o_group_has_right=1
  8550. into :o_right_kind, :o_id_object, :o_objectname
  8551. do
  8552. suspend;
  8553. end
  8554. end^
  8555.  
  8556. SET TERM ; ^
  8557. commit;
  8558.  
  8559. EXECUTE PROCEDURE GIVE_GRANTS_TO_ALL('PROCEDURE','GET_RIGHTS_OF_EMPLOYER_DOCFLOW','EXECUTE');
  8560. commit;
  8561.  
  8562. /* добавляем атрибут "Версия" для видов событий, используемых в настройке оповещений */
  8563. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('NOTIFICATION_PREFS', 'EDITION', 'VARCHAR(10)');
  8564.  
  8565. RESULT
  8566. =======
  8567. 0
  8568.  
  8569. commit;
  8570.  
  8571. /* Заполняем поле "Версия" для видов событий, используемых в настройке оповещений */
  8572. SET TERM ^ ;
  8573. CREATE OR ALTER PROCEDURE TMP_FILL_NOTIF_PREFS_EDITION
  8574. AS
  8575. BEGIN
  8576. UPDATE
  8577. notification_prefs
  8578. SET
  8579. edition = 'docflow'
  8580. WHERE
  8581. action_type in (13, 14, 15, 16);
  8582. UPDATE
  8583. notification_prefs
  8584. SET
  8585. edition = 'workflow'
  8586. WHERE
  8587. action_type in (5, 10, 17);
  8588. END ^
  8589. SET TERM ; ^
  8590. commit;
  8591.  
  8592. EXECUTE PROCEDURE TMP_FILL_NOTIF_PREFS_EDITION;
  8593. commit;
  8594. DROP PROCEDURE TMP_FILL_NOTIF_PREFS_EDITION;
  8595. commit;
  8596.  
  8597. /* добавляем поле "Права на модули" в таблицу employer, значение которого будет определять доступные для пользователя модули в зависимости от лицензий */
  8598. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('EMPLOYER', 'EDITION', 'VARCHAR(10)');
  8599.  
  8600. RESULT
  8601. =======
  8602. 0
  8603.  
  8604. commit;
  8605.  
  8606. /* При обновлении с 1.2 все пользователи получают Complete*/
  8607. SET TERM ^ ;
  8608. CREATE OR ALTER PROCEDURE TMP_SET_COMPLETE_EDITION
  8609. AS
  8610. BEGIN
  8611. UPDATE
  8612. employer
  8613. SET
  8614. edition = 'complete'
  8615. WHERE
  8616. edition is null or edition = '';
  8617. END ^
  8618. SET TERM ; ^
  8619. commit;
  8620.  
  8621. EXECUTE PROCEDURE TMP_SET_COMPLETE_EDITION;
  8622. commit;
  8623. DROP PROCEDURE TMP_SET_COMPLETE_EDITION;
  8624. commit;
  8625. /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  8626. /* WORKFLOW/DOCFLOW/COMPLETE (окончание)
  8627. /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  8628.  
  8629. /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  8630. /* Выделение цветом задач (начало)
  8631. /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  8632. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('TASK_ATTRIBUTE_VALUES', 'COLOR', 'VARCHAR(7)');
  8633.  
  8634. RESULT
  8635. =======
  8636. 0
  8637.  
  8638. commit;
  8639.  
  8640. SET TERM ^ ;
  8641. CREATE OR ALTER PROCEDURE TMP_FILL_COLOR
  8642. AS
  8643. declare variable l_id_md integer;
  8644. declare variable l_id_mf integer;
  8645. declare variable l_task_id integer;
  8646. declare variable l_nrecord_tasktype integer;
  8647. declare variable l_color varchar(7);
  8648. BEGIN
  8649. FOR
  8650. SELECT DISTINCT
  8651. mv.id_md,
  8652. mv.id_mf,
  8653. t.id,
  8654. t.nrecord_tasktype
  8655. FROM
  8656. meta_value mv
  8657. JOIN
  8658. meta_field mf ON (mf.id = mv.id_mf)
  8659. JOIN
  8660. task t ON (t.nrecord_tasktype = mv.id_record)
  8661. WHERE
  8662. mf.id_type_field = 8 AND
  8663. mv.value_integer IN (SELECT
  8664. mv1.id_record
  8665. FROM
  8666. meta_value mv1
  8667. JOIN
  8668. meta_field mf1 ON (mf1.id = mv1.id_mf)
  8669. WHERE
  8670. mv1.isdeleted = 0 AND
  8671. mf1.isdeleted = 0 AND
  8672. mf1.id_type_field = 13) AND
  8673. mv.isdeleted = 0 AND
  8674. t.isdeleted = 0
  8675. INTO
  8676. :l_id_md,
  8677. :l_id_mf,
  8678. :l_task_id,
  8679. :l_nrecord_tasktype
  8680. DO
  8681. BEGIN
  8682. SELECT
  8683. mv.value_char
  8684. FROM
  8685. meta_value mv
  8686. JOIN
  8687. meta_field mf ON (mf.id = mv.id_mf)
  8688. WHERE mv.id_record IN (SELECT
  8689. mv1.value_integer
  8690. FROM
  8691. meta_value mv1
  8692. JOIN
  8693. meta_field mf1 ON (mf1.id = mv1.id_mf)
  8694. WHERE
  8695. mf1.id = :l_id_mf AND
  8696. mv1.id_record = :l_nrecord_tasktype AND
  8697. mv1.id_md = :l_id_md) AND
  8698. mf.id_type_field = 13 AND
  8699. mf.isdeleted = 0 AND
  8700. mv.isdeleted = 0
  8701. INTO
  8702. :l_color;
  8703.  
  8704. IF (l_color <> '') THEN
  8705. BEGIN
  8706. UPDATE
  8707. task_attribute_values
  8708. SET
  8709. color = :l_color
  8710. WHERE
  8711. id_task = :l_task_id AND
  8712. id_metafield = :l_id_mf;
  8713. END
  8714. END
  8715. END ^
  8716. SET TERM ; ^
  8717. commit;
  8718.  
  8719. EXECUTE PROCEDURE TMP_FILL_COLOR;
  8720. commit;
  8721. DROP PROCEDURE TMP_FILL_COLOR;
  8722. commit;
  8723. /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  8724. /* Выделение цветом задач (окончание)
  8725. /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  8726.  
  8727. EXECUTE PROCEDURE ADD_INDEX_IF_DOES_NOT_EXIST('META_FIELD_IDX3', 'META_FIELD', 'ID_CONNECT');
  8728.  
  8729. RESULT
  8730. =======
  8731. 0
  8732.  
  8733. commit;
  8734.  
  8735. EXECUTE PROCEDURE ADD_INDEX_IF_DOES_NOT_EXIST('IDX_FOLDERS_TASKS2', 'FOLDERS_TASKS', 'ID_EMPLOYER,ID_TASK,ID_FOLDER');
  8736.  
  8737. RESULT
  8738. =======
  8739. 0
  8740.  
  8741. commit;
  8742.  
  8743. SET TERM ^ ;
  8744.  
  8745.  
  8746. /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  8747. /* Добавила параметр disableSystemActions - Не уведомлять о системных действиях
  8748. /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  8749. ALTER PROCEDURE INFORMER2_USERPARAMS (
  8750. userid integer)
  8751. returns (
  8752. userclones varchar(2000),
  8753. settings varchar(8000),
  8754. markers varchar(2000),
  8755. activityintervals varchar(2000),
  8756. colorindication varchar(200),
  8757. disablesystemactions integer)
  8758. as
  8759. declare variable id1 integer;
  8760. begin
  8761. UserClones=UserId;
  8762. for select id
  8763. from employer
  8764. where ParentId=:UserId and
  8765. isdeleted=0
  8766. into :id1
  8767. do UserClones=UserClones||','||id1;
  8768. Settings = '';
  8769. ACTIVITYINTERVALS = '';
  8770. MARKERS = '';
  8771. select e.informer_markers, e.colorindication
  8772. from Employer e
  8773. where id= :UserId
  8774. into :MARKERS, :Colorindication;
  8775. SELECT first 1 settings_value
  8776. FROM employer_settings
  8777. WHERE (settings_key='disableSystemActions') AND id_employer = :UserId
  8778. into :disableSystemActions;
  8779. suspend;
  8780. end
  8781. ^
  8782.  
  8783. SET TERM ; ^
  8784. commit;
  8785.  
  8786. /*---------------------------------------------------------------------------------------------*/
  8787. /*удаляем из меню «Дополнительные отчёты» и «Шаблоны отчётов»
  8788. /*----------------------------------------------------------------------------------------------*/
  8789. /*delete from menuitems where ((dmess_tagname = 'L_MENU_CREATE_TEMPLATE') or (dmess_tagname = 'L_MENU_OTHER_REPORTS'));
  8790. commit;
  8791. */
  8792. /*уникальные теги для названий*/
  8793. /*update menuitems mi set mi.dmess_tagname = 'L_MENU_ADMIN_MENUSETTINGS' where mi.item_id = 77;
  8794. commit;
  8795. update menuitems mi set mi.dmess_tagname = 'L_MENU_ADMIN_NOTIFICATION_SETTINGS' where mi.item_id = 74;
  8796. commit;
  8797. */
  8798. /* добавляем поле "Напоминание только для меня" */
  8799. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('NOTICE', 'ONLY_FOR_ME', 'SMALLINT');
  8800.  
  8801. RESULT
  8802. =======
  8803. 0
  8804.  
  8805. COMMIT;
  8806.  
  8807. /* Пункты меню инструменты и сообщения */
  8808. /*execute procedure ADDNEWMENUITEM (NULL,'L_MENU_TOOLS',NULL,0,3,1,0,NULL);
  8809. execute procedure ADDNEWMENUITEM (NULL,'L_MENU_MESSAGES',NULL,0,6,1,0,NULL);
  8810. COMMIT;
  8811. */
  8812. /* Новая структура меню */
  8813. /*SET TERM ^ ;
  8814.  
  8815. CREATE PROCEDURE UPDATE_MENU_4U13
  8816. AS
  8817. DECLARE VARIABLE id INTEGER;
  8818. DECLARE VARIABLE ide INTEGER;
  8819. BEGIN
  8820. // Архив документов в документы
  8821. for
  8822. select mi.ID, mi.ID_EMPLOYER
  8823. from MENUITEMS mi
  8824. where mi.DMESS_TAGNAME='L_MENU_DOCS_ARCHIVE'
  8825. into :id, :ide
  8826. do
  8827. begin
  8828. update MENUITEMS set IDPARENT=
  8829. (select first 1 mi.id
  8830. from MENUITEMS mi
  8831. where mi.DMESS_TAGNAME='L_MENU_DOCUMENTS' and
  8832. mi.ID_EMPLOYER=:ide)
  8833. where ID=:id;
  8834. end
  8835.  
  8836. // Архив задач в задачи /
  8837. for
  8838. select mi.ID, mi.ID_EMPLOYER
  8839. from MENUITEMS mi
  8840. where mi.DMESS_TAGNAME='L_MENU_TARCHIVE'
  8841. into :id, :ide
  8842. do
  8843. begin
  8844. update MENUITEMS set IDPARENT=
  8845. (select first 1 mi.id
  8846. from MENUITEMS mi
  8847. where mi.DMESS_TAGNAME='L_MENU_TASKS' and
  8848. mi.ID_EMPLOYER=:ide)
  8849. where ID=:id;
  8850. end
  8851.  
  8852. Клиентские приложения в инструменты
  8853. for
  8854. select mi.ID, mi.ID_EMPLOYER
  8855. from MENUITEMS mi
  8856. where mi.DMESS_TAGNAME='L_MENU_SOME_PROGRAMMS'
  8857. into :id, :ide
  8858. do
  8859. begin
  8860. update MENUITEMS set IDPARENT=
  8861. (select first 1 mi.id
  8862. from MENUITEMS mi
  8863. where mi.DMESS_TAGNAME='L_MENU_TOOLS' and
  8864. mi.ID_EMPLOYER=:ide)
  8865. where ID=:id;
  8866. end
  8867.  
  8868. Адресная книга в инструменты
  8869. for
  8870. select mi.ID, mi.ID_EMPLOYER
  8871. from MENUITEMS mi
  8872. where mi.DMESS_TAGNAME='L_ADDRESS_BOOK'
  8873. into :id, :ide
  8874. do
  8875. begin
  8876. update MENUITEMS set IDPARENT=
  8877. (select first 1 mi.id
  8878. from MENUITEMS mi
  8879. where mi.DMESS_TAGNAME='L_MENU_TOOLS' and
  8880. mi.ID_EMPLOYER=:ide)
  8881. where ID=:id;
  8882. end
  8883.  
  8884. Отчеты в инструменты
  8885. for
  8886. select mi.ID, mi.ID_EMPLOYER
  8887. from MENUITEMS mi
  8888. where mi.DMESS_TAGNAME='L_MENU_REPORTS'
  8889. into :id, :ide
  8890. do
  8891. begin
  8892. update MENUITEMS set IDPARENT=
  8893. (select first 1 mi.id
  8894. from MENUITEMS mi
  8895. where mi.DMESS_TAGNAME='L_MENU_TOOLS' and
  8896. mi.ID_EMPLOYER=:ide)
  8897. where ID=:id;
  8898. end
  8899.  
  8900. Проекты в инструменты
  8901. for
  8902. select mi.ID, mi.ID_EMPLOYER
  8903. from MENUITEMS mi
  8904. where mi.DMESS_TAGNAME='L_MENU_PROJECTS'
  8905. into :id, :ide
  8906. do
  8907. begin
  8908. update MENUITEMS set IDPARENT=
  8909. (select first 1 mi.id
  8910. from MENUITEMS mi
  8911. where mi.DMESS_TAGNAME='L_MENU_TOOLS' and
  8912. mi.ID_EMPLOYER=:ide)
  8913. where ID=:id;
  8914. end
  8915.  
  8916. Администрирование в инструменты
  8917. for
  8918. select mi.ID, mi.ID_EMPLOYER
  8919. from MENUITEMS mi
  8920. where mi.DMESS_TAGNAME='L_MENU_ADMINISTRATION'
  8921. into :id, :ide
  8922. do
  8923. begin
  8924. update MENUITEMS set IDPARENT=
  8925. (select first 1 mi.id
  8926. from MENUITEMS mi
  8927. where mi.DMESS_TAGNAME='L_MENU_TOOLS' and
  8928. mi.ID_EMPLOYER=:ide)
  8929. where ID=:id;
  8930. end
  8931.  
  8932. Администрирование ДО в инструменты
  8933. for
  8934. select mi.ID, mi.ID_EMPLOYER
  8935. from MENUITEMS mi
  8936. where mi.DMESS_TAGNAME='L_DOCPROCESSING'
  8937. into :id, :ide
  8938. do
  8939. begin
  8940. update MENUITEMS set IDPARENT=
  8941. (select first 1 mi.id
  8942. from MENUITEMS mi
  8943. where mi.DMESS_TAGNAME='L_MENU_TOOLS' and
  8944. mi.ID_EMPLOYER=:ide)
  8945. where ID=:id;
  8946. end
  8947.  
  8948. Система безопасности в инструменты
  8949. for
  8950. select mi.ID, mi.ID_EMPLOYER
  8951. from MENUITEMS mi
  8952. where mi.DMESS_TAGNAME='L_MENU_SECURITY_SYSTEM'
  8953. into :id, :ide
  8954. do
  8955. begin
  8956. update MENUITEMS set IDPARENT=
  8957. (select first 1 mi.id
  8958. from MENUITEMS mi
  8959. where mi.DMESS_TAGNAME='L_MENU_TOOLS' and
  8960. mi.ID_EMPLOYER=:ide)
  8961. where ID=:id;
  8962. end
  8963.  
  8964. Настройки в инструменты
  8965. for
  8966. select mi.ID, mi.ID_EMPLOYER
  8967. from MENUITEMS mi
  8968. where mi.DMESS_TAGNAME='L_AU_MENU_SETTINGS'
  8969. into :id, :ide
  8970. do
  8971. begin
  8972. update MENUITEMS set IDPARENT=
  8973. (select first 1 mi.id
  8974. from MENUITEMS mi
  8975. where mi.DMESS_TAGNAME='L_MENU_TOOLS' and
  8976. mi.ID_EMPLOYER=:ide)
  8977. where ID=:id;
  8978. end
  8979.  
  8980. Архив проектов в проекты
  8981. for
  8982. select mi.ID, mi.ID_EMPLOYER
  8983. from MENUITEMS mi
  8984. where mi.DMESS_TAGNAME='L_MENU_PARCHIVE'
  8985. into :id, :ide
  8986. do
  8987. begin
  8988. update MENUITEMS set IDPARENT=
  8989. (select first 1 mi.id
  8990. from MENUITEMS mi
  8991. where mi.DMESS_TAGNAME='L_MENU_PROJECTS' and
  8992. mi.ID_EMPLOYER=:ide)
  8993. where ID=:id;
  8994. end
  8995.  
  8996. Мои сообщения в сообщения
  8997. for
  8998. select mi.ID, mi.ID_EMPLOYER
  8999. from MENUITEMS mi
  9000. where mi.DMESS_TAGNAME='L_MENU_UIONSENDEDIT'
  9001. into :id, :ide
  9002. do
  9003. begin
  9004. update MENUITEMS set IDPARENT=
  9005. (select first 1 mi.id
  9006. from MENUITEMS mi
  9007. where mi.DMESS_TAGNAME='L_MENU_MESSAGES' and
  9008. mi.ID_EMPLOYER=:ide)
  9009. where ID=:id;
  9010. end
  9011.  
  9012. Порядок пунктов меню
  9013. update MENUITEMS mi
  9014. set mi.NUMBER=1
  9015. WHERE mi.DMESS_TAGNAME='L_MENU_TASKS';
  9016.  
  9017. update MENUITEMS mi
  9018. set mi.NUMBER=2
  9019. WHERE mi.DMESS_TAGNAME='L_MENU_DOCUMENTS';
  9020.  
  9021. update MENUITEMS mi
  9022. set mi.NUMBER=3
  9023. WHERE mi.DMESS_TAGNAME='L_MENU_MESSAGES';
  9024.  
  9025. update MENUITEMS mi
  9026. set mi.NUMBER=4
  9027. WHERE mi.DMESS_TAGNAME='L_GLOBAL_CALENDAR';
  9028.  
  9029. update MENUITEMS mi
  9030. set mi.NUMBER=5
  9031. WHERE mi.DMESS_TAGNAME='L_MENU_DOCLIBRARY';
  9032.  
  9033. update MENUITEMS mi
  9034. set mi.NUMBER=6
  9035. WHERE mi.DMESS_TAGNAME='L_MENU_TOOLS';
  9036.  
  9037. update MENUITEMS mi
  9038. set mi.NUMBER=1
  9039. WHERE mi.DMESS_TAGNAME='L_INFORMER_CREATETASK';
  9040.  
  9041. update MENUITEMS mi
  9042. set mi.NUMBER=2
  9043. WHERE mi.DMESS_TAGNAME='L_MENU_UNIONTASKS';
  9044.  
  9045. update MENUITEMS mi
  9046. set mi.NUMBER=3
  9047. WHERE mi.DMESS_TAGNAME='L_MENU_ONCONTROL';
  9048.  
  9049. update MENUITEMS mi
  9050. set mi.NUMBER=4
  9051. WHERE mi.DMESS_TAGNAME='L_MENU_TASKSANDEMP';
  9052.  
  9053. update MENUITEMS mi
  9054. set mi.NUMBER=5
  9055. WHERE mi.DMESS_TAGNAME='L_MENU_TARCHIVE';
  9056.  
  9057. delete from MENUITEMS mi
  9058. WHERE mi.DMESS_TAGNAME='L_MENU_MYTASKS';
  9059.  
  9060. delete from MENUITEMS mi
  9061. WHERE mi.DMESS_TAGNAME='L_MENU_TASKSFROMME';
  9062.  
  9063. update MENUITEMS mi
  9064. set mi.NUMBER=1
  9065. WHERE mi.DMESS_TAGNAME='L_DOCUMENT_NEW';
  9066.  
  9067. update MENUITEMS mi
  9068. set mi.NUMBER=2
  9069. WHERE mi.DMESS_TAGNAME='L_MENU_MYDOCS_FORASSIGNMENT';
  9070.  
  9071. update MENUITEMS mi
  9072. set mi.NUMBER=3
  9073. WHERE mi.DMESS_TAGNAME='L_MENU_MYDOCS_FOREXECUTION';
  9074.  
  9075. update MENUITEMS mi
  9076. set mi.NUMBER=4
  9077. WHERE mi.DMESS_TAGNAME='L_MENU_DOCS_ONASSIGNMENT';
  9078.  
  9079. update MENUITEMS mi
  9080. set mi.NUMBER=5
  9081. WHERE mi.DMESS_TAGNAME='L_MENU_DOCS_ONEXECUTION';
  9082.  
  9083. update MENUITEMS mi
  9084. set mi.NUMBER=6
  9085. WHERE mi.DMESS_TAGNAME='L_MENU_DOCS_FROMME';
  9086.  
  9087. update MENUITEMS mi
  9088. set mi.NUMBER=7
  9089. WHERE mi.DMESS_TAGNAME='L_MENU_DOCS_REGISTRY';
  9090.  
  9091. update MENUITEMS mi
  9092. set mi.NUMBER=8
  9093. WHERE mi.DMESS_TAGNAME='L_MENU_DOCS_DETAL_REGISTRY_COUNTERS';
  9094.  
  9095. update MENUITEMS mi
  9096. set mi.NUMBER=9
  9097. WHERE mi.DMESS_TAGNAME='L_MENU_DOCUMENT_STATISTIC';
  9098.  
  9099. update MENUITEMS mi
  9100. set mi.NUMBER=10
  9101. WHERE mi.DMESS_TAGNAME='L_MENU_DOCS_REPORT';
  9102.  
  9103. update MENUITEMS mi
  9104. set mi.NUMBER=11
  9105. WHERE mi.DMESS_TAGNAME='L_MENU_DOCS_ARCHIVE';
  9106.  
  9107. update MENUITEMS mi
  9108. set mi.url='/user/notices/'
  9109. where mi.DMESS_TAGNAME='L_MENU_UIONSENDEDIT';
  9110.  
  9111. update MENUITEMS mi
  9112. set mi.NUMBER=23
  9113. WHERE mi.DMESS_TAGNAME='L_MENU_ADRESSBOOK_SETTINGS';
  9114.  
  9115. update MENUITEMS mi
  9116. set mi.NUMBER=16
  9117. WHERE mi.DMESS_TAGNAME='L_GLOBAL_USE_STATISTIC';
  9118.  
  9119. update MENUITEMS mi
  9120. set mi.NUMBER=10
  9121. WHERE mi.DMESS_TAGNAME='L_GLOBAL_EMAIL_EMPLOYER_GROUPS';
  9122.  
  9123. update MENUITEMS mi
  9124. set mi.NUMBER=4
  9125. WHERE mi.DMESS_TAGNAME='L_SEARCHING_DOCUMENTS';
  9126.  
  9127. update MENUITEMS mi
  9128. set mi.NUMBER=5
  9129. WHERE mi.DMESS_TAGNAME='L_MENU_PARCHIVE';
  9130.  
  9131. /*Права на пункты меню начало*/
  9132. /*администрирование*/
  9133. /*показывать группу "администрирование" если начальник, любой админ, право на создание типов задач или право
  9134. на просмотр записей справочников или на администрирование справочников*/
  9135. --update menuitems mi set mi.right_kind = 11 where mi.dmess_tagname = 'L_MENU_ADMINISTRATION';
  9136. /*администрирование до для админов до*/
  9137. --update menuitems mi set mi.right_kind = 4 where mi.dmess_tagname = 'L_DOCPROCESSING';
  9138. /*система безопастности*/
  9139. /*по идее, должен быть доступен любому админу - есть пункт "отчет по удаленным документам", но при ситуации
  9140. когда кто-то админ библиотеки и workflow меню виснет - группа видна из-за этого пункта для любого админа, а ему
  9141. нелизя ничего связанного с документами. поэтому 12 - все админы, но админ библиотеки еще и не workflow*/
  9142. --update menuitems mi set mi.right_kind = 12 where mi.dmess_tagname = 'L_MENU_SECURITY_SYSTEM';
  9143. /*функционал формализованных документов*/
  9144. /*видимый для админа до при включенной опции формализованных документов*/
  9145. --update menuitems mi set mi.right_kind = 13 where mi.dmess_tagname = 'L_MENU_FORMALDOCUMENT_TEMPLATE_EDITOR';
  9146. /*вроде как для шаблонов документов используется этот тег и ид*/
  9147. --update menuitems mi set mi.right_kind = 13 where mi.dmess_tagname = 'L_AU_DOCUMENT_TEMPLATE_EDITOR';
  9148. /*но у нас на бете для всех юзеров еще и этот пункт есть. заменим и тут*/
  9149. --update menuitems mi set mi.right_kind = 13 where mi.dmess_tagname = 'L_MENU_FORMALDOCUMENT_TEMPLATE_EDITOR';
  9150. /*удаляем из администрирования "объявления"*/
  9151. --delete from menuitems mi where mi.dmess_tagname ='L_MENU_NOTICES';
  9152. /* удаляем лишние пункты меню проекты */
  9153. --delete from menuitems mi where mi.dmess_tagname = 'L_MENU_PROJECTS' and ((mi.item_id > 0) or (mi.idparent is null));
  9154. /*у некоторых пользователей откуда-то взялся лишний пункт "поиск"*/
  9155. --delete from menuitems mi where mi.dmess_tagname = 'L_GLOBAL_SEARCH' and mi.number = 13;
  9156. /*удаляем пункт "архивы"*/
  9157. --delete from menuitems mi where mi.dmess_tagname = 'L_MENU_ARCHIVES';
  9158. /*лишний пунк администрирование в настройках по умолчанию*/
  9159. --delete from menuitems m where m.dmess_tagname = 'L_MENU_ADMINISTRATION' and m.isdefvisible is null and m.id_employer = -1;
  9160. /*в двух отчетах не стоят слеши в адресах, поэтому они не открываются. фиксим*/
  9161. /*статистика по задачам пользователя*/
  9162. --update menuitems mi set mi.url = '/user/prereporttasksonperiod/' where mi.dmess_tagname = 'L_MENU_TASKS_ON_PERIOD';
  9163. /*общий отчет по пользователям*/
  9164. --update menuitems mi set mi.url = '/user/user_report/' where mi.dmess_tagname = 'L_GLOBAL_USERS_REPORT';
  9165. /*адрессная книга теперь не группа, ей нуже ид*/
  9166. --update menuitems m set m.item_id = 32 where m.dmess_tagname = 'L_ADDRESS_BOOK';
  9167. /*Права на пункты меню конец*/
  9168.  
  9169. /* удаляем пункты меню Настройки - Фильтры подразделений и Настройки - Группы */
  9170. /*delete from MENUITEMS mi where mi.DMESS_TAGNAME = 'L_MENU_USER_DEPARTMENT';
  9171. delete from MENUITEMS mi where mi.DMESS_TAGNAME = 'L_MENU_GROUPS';
  9172. delete from MENUITEMS mi where mi.DMESS_TAGNAME = 'L_MENU_NOTICES';
  9173. END^
  9174.  
  9175. SET TERM ; ^
  9176.  
  9177. COMMIT;
  9178.  
  9179. EXECUTE PROCEDURE UPDATE_MENU_4U13;
  9180. COMMIT;
  9181.  
  9182. DROP PROCEDURE UPDATE_MENU_4U13;
  9183. COMMIT;
  9184. */
  9185.  
  9186. /*-------------------------------------------------------------------------------------------------------------------------------*/
  9187. /*После того, как меню стало не иерархичным, информации из ADDNEWMENUITEM недостаточно
  9188. для идентификации родительского элемента там использовалась пара "позиция в группе+нет родителя", теперь это не уникальное значение
  9189. получается,
  9190. в этой процедуре добавляем пункт в меню по тегу группы*/
  9191. /*-------------------------------------------------------------------------------------------------------------------------------*/
  9192. SET TERM ^ ;
  9193.  
  9194. CREATE OR ALTER PROCEDURE ADDMENUITEMBYTAG (
  9195. i_item_id integer,
  9196. i_dmess_tagname varchar(200),
  9197. i_url varchar(1000),
  9198. i_parent_tag varchar(200),/*тег родительской группы*/
  9199. i_number smallint,
  9200. i_isdefvisible smallint,
  9201. i_right_kind smallint,
  9202. i_edition varchar(10))
  9203. as
  9204. declare variable l_id_employer integer;
  9205. declare variable l_idparent integer;
  9206. begin
  9207. l_idparent = null;
  9208. select first 1 id from menuitems m where m.item_id is null and m.id_employer=0 and m.dmess_tagname=:i_parent_tag
  9209. into :l_idparent;
  9210. /*если такого пункта нет, или он не группа ничего не добавляем*/
  9211. if (l_idparent is null) then
  9212. exit;
  9213. else
  9214. /*если уже есть с таким идшником, то не добавляем*/
  9215. if (exists(select id
  9216. from menuitems
  9217. where item_id=:i_item_id)) then exit;
  9218. update menuitems m
  9219. set m.number = m.number + 1
  9220. where m.id_employer=0 and m.idparent=:l_idparent and m.number>=:i_number;
  9221. /*достаем экземпляр группы отдельно для -1*/
  9222. select first 1 id from menuitems m where m.item_id is null and m.id_employer=-1 and m.dmess_tagname=:i_parent_tag
  9223. into :l_idparent;
  9224.  
  9225. insert into menuitems (item_id,dmess_tagname,url,idparent,number,
  9226. isdefvisible,right_kind,id_employer,edition)
  9227. values (:i_item_id, :i_dmess_tagname, :i_url, :l_idparent, :i_number,
  9228. :i_isdefvisible, :i_right_kind, -1, :i_edition);
  9229. /*и для 0*/
  9230. select first 1 id from menuitems m where m.item_id is null and m.id_employer=0 and m.dmess_tagname=:i_parent_tag
  9231. into :l_idparent;
  9232.  
  9233. insert into menuitems (item_id,dmess_tagname,url,idparent,number,
  9234. isdefvisible,right_kind,id_employer,edition)
  9235. values (:i_item_id, :i_dmess_tagname, :i_url, :l_idparent, :i_number,
  9236. :i_isdefvisible, :i_right_kind, 0, :i_edition);
  9237. /*и для каждого юзера*/
  9238. for select e.id from employer e
  9239. where e.isdeleted=0 and e.parentid is null and
  9240. (exists (select first 1 m.id from menuitems m where m.id_employer=e.id and m.dmess_tagname=:i_parent_tag))
  9241. into :l_id_employer
  9242. do
  9243. begin
  9244. select first 1 id from menuitems m
  9245. where m.item_id is null and m.id_employer=:l_id_employer and m.dmess_tagname=:i_parent_tag
  9246. into :l_idparent;
  9247.  
  9248. update menuitems m
  9249. set m.number = m.number + 1
  9250. where m.id_employer=:l_id_employer and m.idparent=:l_idparent and m.number>=:i_number;
  9251. insert into menuitems (item_id,dmess_tagname,url,idparent,number,
  9252. right_kind,id_employer,edition)
  9253. values (:i_item_id, :i_dmess_tagname, :i_url, :l_idparent, :i_number,
  9254. :i_right_kind, :l_id_employer, :i_edition);
  9255. end
  9256. end^
  9257.  
  9258. SET TERM ; ^
  9259. commit;
  9260. SET TERM ^ ;
  9261.  
  9262. CREATE OR ALTER PROCEDURE COPYMENUITEMS (
  9263. i_id_employer integer)
  9264. as
  9265. /*процедура копирует пункты меню пользователя 0 для нового пользователя*/
  9266. /*пункты из корня*/
  9267. declare variable l_id integer;
  9268. declare variable l_item_id integer;
  9269. declare variable l_dmess_tagname varchar(200);
  9270. declare variable l_url varchar(1000);
  9271. declare variable l_number smallint;
  9272. declare variable l_isvisible smallint;
  9273. declare variable l_right_kind smallint;
  9274. declare variable l_edition varchar(10);
  9275. /*пункты первого уровня*/
  9276. declare variable l_id2 integer;
  9277. declare variable l_item_id2 integer;
  9278. declare variable l_dmess_tagname2 varchar(200);
  9279. declare variable l_url2 varchar(1000);
  9280. declare variable l_number2 smallint;
  9281. declare variable l_isvisible2 smallint;
  9282. declare variable l_isdefvisible2 smallint;
  9283. declare variable l_right_kind2 smallint;
  9284. declare variable l_edition2 varchar(10);
  9285. /*пункты второго уровня*/
  9286. declare variable l_id3 integer;
  9287. declare variable l_item_id3 integer;
  9288. declare variable l_dmess_tagname3 varchar(200);
  9289. declare variable l_url3 varchar(1000);
  9290. declare variable l_number3 smallint;
  9291. declare variable l_isvisible3 smallint;
  9292. declare variable l_isdefvisible3 smallint;
  9293. declare variable l_right_kind3 smallint;
  9294. declare variable l_edition3 varchar(10);
  9295. /*РіСЂСѓРїРїР° РІ РєРѕСЂРЅРµ*/
  9296. declare variable l_id_new integer;
  9297. /*группа первого уровня*/
  9298. declare variable l_sub_id_new integer;
  9299. begin
  9300. /*копируем корневые элементы*/
  9301. for select
  9302. m.id, m.item_id, m.dmess_tagname, m.url, m.number,
  9303. m.isvisible, m.right_kind, m.edition
  9304. from menuitems m
  9305. where m.id_employer=0 and m.idparent=0
  9306. into :l_id,:l_item_id,:l_dmess_tagname,:l_url,:l_number,
  9307. :l_isvisible,:l_right_kind,:l_edition
  9308. do
  9309. begin
  9310. l_id_new = gen_id(gen_menuitems_id,1);
  9311. insert into menuitems (id,item_id,dmess_tagname,url,number,isvisible,right_kind,id_employer,edition)
  9312. values (:l_id_new,:l_item_id,:l_dmess_tagname,:l_url,:l_number,:l_isvisible,:l_right_kind,:i_id_employer,:l_edition);
  9313. /*коприруем элементы первого уровня*/
  9314. for select
  9315. m.id, m.item_id, m.dmess_tagname, m.url, m.number,
  9316. m.isvisible, m.isdefvisible, m.right_kind, m.edition
  9317. from menuitems m
  9318. where m.id_employer=0 and m.idparent=:l_id
  9319. into :l_id2,:l_item_id2,:l_dmess_tagname2,:l_url2,:l_number2,
  9320. :l_isvisible2,:l_isdefvisible2,:l_right_kind2,:l_edition2
  9321. do
  9322. begin
  9323. l_sub_id_new = gen_id(gen_menuitems_id,1);
  9324. insert into menuitems (id,item_id,dmess_tagname,url,number,isvisible,right_kind,idparent,id_employer,edition)
  9325. values (:l_sub_id_new,:l_item_id2,:l_dmess_tagname2,:l_url2,:l_number2,:l_isvisible2,:l_right_kind2,:l_id_new,:i_id_employer,:l_edition2);
  9326. if (l_item_id2 is null) then /*и для тех, у кого есть потомки*/
  9327. for select/*коприруем элементы второго уровня*/
  9328. m.id, m.item_id, m.dmess_tagname, m.url, m.number,
  9329. m.isvisible, m.isdefvisible, m.right_kind, m.edition
  9330. from menuitems m
  9331. where m.id_employer=0 and m.idparent=:l_id2
  9332. into :l_id3,:l_item_id3,:l_dmess_tagname3,:l_url3,:l_number3,
  9333. :l_isvisible3,:l_isdefvisible3,:l_right_kind3,:l_edition3
  9334. do
  9335. begin
  9336. insert into menuitems (item_id,dmess_tagname,url,number,isvisible,right_kind,idparent,id_employer,edition)
  9337. values (:l_item_id3,:l_dmess_tagname3,:l_url3,:l_number3,:l_isvisible3,:l_right_kind3,:l_sub_id_new,:i_id_employer,:l_edition3);
  9338. end
  9339.  
  9340. end
  9341. end
  9342. end^
  9343.  
  9344. SET TERM ; ^
  9345. commit;
  9346. /*-------------------------------------------------------------------------------------------------------------------------------*/
  9347. /* Копирование пунктов меню - конец*/
  9348. /*-------------------------------------------------------------------------------------------------------------------------------*/
  9349.  
  9350.  
  9351. SET TERM ^ ;
  9352.  
  9353. CREATE OR ALTER PROCEDURE GETALLNOTICES (
  9354. i_employer_id integer,
  9355. i_date timestamp)
  9356. returns (
  9357. o_notice_id integer,
  9358. o_noticename varchar(200),
  9359. o_author_id integer,
  9360. o_authorname varchar(200),
  9361. o_createdate timestamp,
  9362. o_showdate timestamp,
  9363. o_employercount integer,
  9364. o_employerviewed integer,
  9365. o_noticetype integer,
  9366. o_description varchar(10000),
  9367. o_id_task integer,
  9368. o_place varchar(200),
  9369. o_isshowtasklink smallint,
  9370. o_is_view integer)
  9371. as
  9372. declare variable l_result integer;
  9373. begin
  9374. for select /*distinct*/
  9375. n.id,
  9376. n.name,
  9377. n.id_author,
  9378. (select name from employer e where e.id = n.id_author),
  9379. n.createdate,
  9380. n.showdate,
  9381. n.noticetype,
  9382. n.description,
  9383. n.id_task,
  9384. n.place,
  9385. n.isshowtasklink
  9386. from notice n
  9387. where n.isdeleted=0 and ((n.id_author=:i_employer_id and (n.noticetype = 1 or n.noticetype = 3 or n.noticetype = 0)) or
  9388. n.id in (select ntv.id_notice from noticeview ntv where ntv.id_employer=:i_employer_id and ntv.isviewed = 0 and ntv.showdate <= :i_date))
  9389. /*((ntv.id_employer=:i_employer_id and ntv.isviewed = 0) or n.id_author=:i_employer_id)*/
  9390. into
  9391. :o_notice_id,
  9392. :o_noticename,
  9393. :o_author_id,
  9394. :o_authorname,
  9395. :o_createdate,
  9396. :o_showdate,
  9397. :o_noticetype,
  9398. :o_description,
  9399. :o_id_task,
  9400. :o_place,
  9401. :o_isshowtasklink
  9402. do
  9403. begin
  9404. /*if (o_employercount is null) then
  9405. o_employercount=0;
  9406. o_employercount = o_employercount+1; */
  9407. o_employercount=0;
  9408. select count(*)
  9409. from noticeview nw
  9410. where nw.id_notice=:o_notice_id
  9411. into :o_employercount;
  9412. o_employerviewed=0;
  9413. select count(*)
  9414. from noticeview nw
  9415. where nw.id_notice=:o_notice_id and nw.isviewed=1
  9416. into :o_employerviewed;
  9417. select count(*)
  9418. from noticeview nw
  9419. where nw.id_notice=:o_notice_id and id_employer=:i_employer_id and isviewed = 0 and nw.showdate <= :i_date
  9420. into :o_is_view;
  9421. suspend;
  9422. end
  9423. end^
  9424.  
  9425. SET TERM ; ^
  9426. commit;
  9427.  
  9428. /*-------------------------------------------------------------------------------------------------------------------------------*/
  9429. /*у пользователя по умолчанию -1 путаница с меню. началась еще с древних версий каких-то . чистим теперь*/
  9430. /*-------------------------------------------------------------------------------------------------------------------------------*/
  9431. /*SET TERM ^ ;
  9432.  
  9433. CREATE OR ALTER PROCEDURE CLEANDEFMENUSET
  9434. as
  9435. declare variable l_tag_parent varchar(200);
  9436. declare variable l_id_parant integer;
  9437. declare variable l_tag_item varchar(200);
  9438. declare variable l_id_item integer;
  9439. begin
  9440. for select m.id, m.dmess_tagname
  9441. from menuitems m
  9442. where m.id_employer = -1 and m.idparent not in
  9443. (select n.id from menuitems n where n.id_employer = -1)
  9444. and m.idparent <> 0
  9445. into
  9446. :l_id_item,
  9447. :l_tag_item
  9448. do
  9449. begin
  9450. select first 1 m.idparent from menuitems m where m.id_employer = 0 and m.dmess_tagname = :l_tag_item
  9451. into
  9452. :l_id_parant;
  9453. select first 1 m.dmess_tagname from menuitems m where m.id_employer = 0 and m.id = :l_id_parant
  9454. into
  9455. :l_tag_parent;
  9456. update menuitems n set n.idparent = (select first 1 m.id from menuitems m
  9457. where m.id_employer = -1 and m.dmess_tagname = :l_tag_parent)
  9458. where n.id = :l_id_item and n.id_employer = -1;
  9459. end
  9460. end^
  9461.  
  9462. SET TERM ; ^
  9463. commit;
  9464.  
  9465. execute procedure cleandefmenuset;
  9466. commit;
  9467. */
  9468. EXECUTE PROCEDURE ADD_INDEX_IF_DOES_NOT_EXIST('IDX_ACTIONS1','ACTIONS','ID_PARENT_ACTION');
  9469.  
  9470. RESULT
  9471. =======
  9472. 0
  9473.  
  9474. COMMIT;
  9475.  
  9476. /* Уникальные логины в системе */
  9477.  
  9478. CREATE OR ALTER EXCEPTION eBadLogin 'Login already exists';
  9479.  
  9480. SET TERM ^ ;
  9481.  
  9482. CREATE OR ALTER TRIGGER EMPLOYER_BIU FOR EMPLOYER
  9483. ACTIVE BEFORE INSERT OR UPDATE POSITION 0
  9484. AS
  9485. DECLARE lUserId INTEGER;
  9486. BEGIN
  9487. IF (NEW.parentid IS NULL AND NEW.id <> OLD.id) THEN
  9488. BEGIN
  9489. SELECT id
  9490. FROM employer e
  9491. WHERE e.login = NEW.login AND
  9492. e.parentid IS NULL AND
  9493. e.isdeleted = 0
  9494. INTO :lUserId;
  9495. IF (:lUserId IS NOT NULL) THEN EXCEPTION eBadLogin;
  9496. END
  9497. END^
  9498.  
  9499. SET TERM ; ^
  9500.  
  9501. COMMIT;
  9502.  
  9503. SET TERM ^ ;
  9504. CREATE OR ALTER PROCEDURE GETDOCUMENTS_ARCHIVE_MY (
  9505. i_employer_id integer,
  9506. i_createdate_from timestamp,
  9507. i_createdate_to timestamp)
  9508. returns (
  9509. o_doc_type integer,
  9510. o_docid integer,
  9511. o_is_right_arhiv integer) /*1 если попадает, 0 - нет*/
  9512. as
  9513. declare variable is_emplouer integer; /*есть права на автора*/
  9514. declare variable is_autor integer; /*есть права на участника задач по документу*/
  9515. begin
  9516. for select d.id, (select p.ID_Boss
  9517. from permission p
  9518. where p.ID_Boss = :i_employer_id
  9519. and p.ID_Employer = d.id_author
  9520. and p.enabled = 1
  9521. ), d.id_doctype
  9522. from documents d
  9523. where d.createdate >= :i_createdate_from and d.createdate <= :i_createdate_to
  9524. and d.state = 4 and d.isdeleted = 0
  9525. into :o_docid,
  9526. :is_autor,
  9527. :o_doc_type
  9528. do
  9529. /*----------------------------------------------------------------------------------------*/
  9530. /*если есть права на атора документа, то все, в архив попадает*/
  9531. if (is_autor <> 0) then
  9532. begin
  9533. O_IS_RIGHT_ARHIV = 1;
  9534. suspend;
  9535. end
  9536. /*----------------------------------------------------------------------------------------*/
  9537. /*если нет, проверяем права на участников задач по документу (с ботами блин)*/
  9538. else
  9539. begin
  9540. select count (g.task_id_document)
  9541. from grouptask g
  9542. where g.task_id_document = :o_docid
  9543. and g.id_employer in (select p.id_employer from permission p
  9544. where p.id_boss = :i_employer_id
  9545. and p.enabled = 1)
  9546. into :is_emplouer;
  9547. /*----------------------------------------------------------------------------------------*/
  9548. /*если подходящие задачи есть, то все ок, попадает в отчет*/
  9549. if (is_emplouer <> 0) then
  9550. begin
  9551. O_IS_RIGHT_ARHIV = 1;
  9552. end
  9553. /*----------------------------------------------------------------------------------------*/
  9554. /*если нет, то без вариантов - этого документа в отчете нет*/
  9555. else
  9556. begin
  9557. O_IS_RIGHT_ARHIV = 0;
  9558. end
  9559. suspend;
  9560. end
  9561. end^
  9562.  
  9563. SET TERM ; ^
  9564. commit;
  9565. SET TERM ^ ;
  9566. CREATE OR ALTER PROCEDURE MENUTRESH
  9567. as
  9568. declare variable var_emp integer;
  9569. declare variable chest_first_time integer;
  9570. begin
  9571. --проверка: если у "создать задачу" ид = 101, то эта процедура уже выполнялась и больше не надо
  9572. for select m.item_id from menuitems m
  9573. where m.id_employer = 0 and m.dmess_tagname = 'L_INFORMER_CREATETASK'
  9574. into :chest_first_time
  9575. do
  9576. begin
  9577. if (chest_first_time = 101) then exit;
  9578. end
  9579. --дропаем таблицу
  9580. delete from menuitems;
  9581. chest_first_time = GEN_ID(GEN_MENUITEMS_ID, -GEN_ID(GEN_MENUITEMS_ID, 0));
  9582. chest_first_time = GEN_ID(GEN_MENUITEMS_ID, 1000);
  9583. --правильное меню
  9584. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (10, NULL, 'L_MENU_TASKS', NULL, 0, 1, 1, 1, 0, 0, NULL);
  9585. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (20, NULL, 'L_MENU_IAP', NULL, 0, 2, 1, 1, 30, 0, NULL);
  9586. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (30, NULL, 'L_MENU_IAP_PROJECT', 'l_menu_iap_project_adress', 0, 3, 1, 1, 30, 0, NULL);
  9587. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (40, NULL, 'L_MENU_DOCUMENTS', NULL, 0, 4, 1, 1, 0, 0, 'docflow');
  9588. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (50, NULL, 'L_MENU_MESSAGES', NULL, 0, 5, 1, 1, 0, 0, NULL);
  9589. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (60, NULL, 'L_GLOBAL_CALENDAR', '/user/calendarreportsel', 0, 6, 1, 1, 0, 0, NULL);
  9590. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (70, NULL, 'L_MENU_DOCLIBRARY', NULL, 0, 7, 1, 1, 0, 0, NULL);
  9591. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (80, NULL, 'L_MENU_TOOLS', NULL, 0, 8, 1, 1, 0, 0, NULL);
  9592. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (90, NULL, 'L_ADDITIONAL', NULL, 0, 9, 1, 1, 0, 0, NULL);
  9593. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (95, NULL, 'L_GLOBAL_SEARCH', NULL, 0, 10, 1, 1, 0, 0, NULL);
  9594. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (101, 101, 'L_INFORMER_CREATETASK', '/user/tasks//add/create_task/', 10, 2, 1, 1, 0, 0, 'workflow');
  9595. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (102, 102, 'L_MENU_UNIONTASKS', '/user/uniontasks/', 10, 1, 1, 1, 0, 0, NULL);
  9596. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (103, 103, 'L_MENU_ONCONTROL', '/user/formycontrol', 10, 5, 1, 0, 0, 0, NULL);
  9597. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (104, 104, 'L_MENU_TASKSANDEMP', '/user/tasks/', 10, 3, 1, 1, 0, 0, NULL);
  9598. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (105, 105, 'L_MENU_TARCHIVE', '/user/prereport/archive/', 10, 4, 1, 1, 0, 0, NULL);
  9599. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (201, 201, 'L_MENU_IAP_TASKS', '/user/tasksreports_grid/iap_message/', 20, 1, 1, 1, 30, 0, NULL);
  9600. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (202, 202, 'L_MENU_TABLE_TYPES', 'l_menu_table_types_adress', 20, 2, 1, 1, 30, 0, NULL);
  9601. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (203, 201, 'L_MENU_IAP_ADMINISTRATION', '/motiw4/Motiw4/Motiw4.html?sessionover=1', 20, 3, 1, 1, 30, 0, NULL);
  9602. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (401, 401, 'L_MENU_MYDOCS_FORASSIGNMENT', '/documents/mysigndocuments2/grid/mysigndocuments', 40, 1, 1, 1, 0, 0, 'docflow');
  9603. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (402, 402, 'L_MENU_MYDOCS_FOREXECUTION', '/documents/mysigndocuments2/grid/myexecdocuments', 40, 2, 1, 1, 0, 0, 'docflow');
  9604. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (403, 403, 'L_MENU_DOCS_ONASSIGNMENT', '/user/prereport/signdocuments2/', 40, 3, 1, 1, 2, 0, 'docflow');
  9605. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (404, 404, 'L_MENU_DOCS_ONEXECUTION', '/user/prereport/execdocuments2/', 40, 4, 1, 1, 2, 0, 'docflow');
  9606. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (405, 405, 'L_DOCUMENT_NEW', '/documents/newdocument/', 40, 5, 1, 1, 1, 0, 'docflow');
  9607. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (406, 406, 'L_MENU_DOCS_FROMME', '/documents/mysigndocuments2/grid/signdocumentsfromme', 40, 6, 1, 1, 1, 0, 'docflow');
  9608. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (407, 407, 'L_MENU_DOCS_REGISTRY', '/user/prereport/documents_registry2/', 40, 7, 1, 1, 2, 0, 'docflow');
  9609. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (408, 408, 'L_MENU_DOCS_DETAL_REGISTRY_COUNTERS', '/user/prereport/documents_registry_detal', 40, 8, 1, 1, 2, 0, 'docflow');
  9610. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (409, 409, 'L_MENU_DOCS_REPORT', '/user/prereport/report_documents/', 40, 9, 1, 1, 2, 0, 'docflow');
  9611. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (410, 410, 'L_MENU_DOCUMENT_STATISTIC', '/user/prereport/documents_statistic', 40, 10, 1, 1, 4, 0, 'docflow');
  9612. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (411, 411, 'L_MENU_DOCS_ARCHIVE', '/user/prereport_seldoctype/document_archive/', 40, 11, 1, 1, 22, 0, 'docflow');
  9613. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (701, 701, 'L_GLOBAL_DL_VIEW_DOCLIB', '/user/doclibview', 70, 1, 1, 1, 0, 0, NULL);
  9614. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (702, 702, 'L_GLOBAL_DL_CREATE_EDIT_FOLDER', '/user/createdltree', 70, 2, 1, 1, 0, 0, NULL);
  9615. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (703, 703, 'L_GLOBAL_DL_CHANGE_RIGHTS_TO_FOLDER', '/user/dlpermission', 70, 3, 1, 1, 0, 0, NULL);
  9616. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (704, 704, 'L_USER_RIGHTS_ON_DLFOLDER', '/user/userrightsondlfolder', 70, 4, 1, 1, 0, 0, NULL);
  9617. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (81, 81, 'L_ADDRESS_BOOK', '/user/tree_address_book', 80, 1, 1, 1, 0, 0, NULL);
  9618. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (82, NULL, 'L_MENU_REPORTS', NULL, 80, 2, 1, 1, 0, 0, NULL);
  9619. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (83, NULL, 'L_MENU_PROJECTS', NULL, 80, 3, 1, 1, 0, 0, NULL);
  9620. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (84, NULL, 'L_MENU_ADMINISTRATION', NULL, 80, 4, 1, 1, 11, 0, NULL);
  9621. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (86, NULL, 'L_DOCPROCESSING', NULL, 80, 5, 1, 1, 4, 0, 'docflow');
  9622. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (87, NULL, 'L_MENU_SECURITY_SYSTEM', NULL, 80, 6, 1, 1, 12, 0, NULL);
  9623. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (88, NULL, 'L_AU_MENU_SETTINGS', NULL, 80, 7, 1, 1, 0, 0, NULL);
  9624. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (89, 503, 'L_MENU_SOME_PROGRAMMS', '/user/some_programms/', 80, 8, 1, 1, 0, 0, NULL);
  9625. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (821, 821, 'L_MENU_ACTIONTAPE', '/user/prereport/report1/', 82, 1, 1, 1, 0, 0, NULL);
  9626. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (822, 822, 'L_MENU_ACTONMYTASKS', '/user/prereport/report8/', 82, 2, 1, 1, 0, 0, NULL);
  9627. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (823, 823, 'L_MENU_TASK_SUPERREPORT', '/user/prereport_selusers/tasksuperreport', 82, 3, 1, 1, 0, 0, NULL);
  9628. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (824, 824, 'L_GLOBAL_USERS_REPORT', '/user/user_report/', 82, 4, 1, 0, 0, 0, NULL);
  9629. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (825, 825, 'L_MENU_CUREMPTASKS', '/user/prereport_selusers/currentusertasks/', 82, 5, 1, 1, 0, 0, NULL);
  9630. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (826, 826, 'L_MENU_TASKSPERDIV', '/user/report4/', 82, 6, 1, 1, 0, 0, NULL);
  9631. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (827, 827, 'L_MENU_OUTDATEDTASKS', '/user/prereport/r_outdated/', 82, 7, 1, 1, 0, 0, NULL);
  9632. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (828, 828, 'L_MENU_TASKS_ON_PERIOD', '/user/prereporttasksonperiod/', 82, 8, 1, 1, 0, 0, NULL);
  9633. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (829, 829, 'L_REPORT_EXEC_BUT_OUTDATES', '/user/prereport/exec_but_outdate/', 82, 9, 1, 1, 0, 0, NULL);
  9634. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (830, 830, 'L_MENU_USERPROPS', '/user/report_users/', 82, 10, 1, 1, 0, 0, NULL);
  9635. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (831, 831, 'L_AU_PERMISSIONS_OF_EMPLOYER', '/user/whohasrights', 82, 11, 1, 1, 0, 0, NULL);
  9636. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (832, 832, 'L_GLOBAL_USER_REPORTS', '/user/free_plugins', 82, 12, 1, 0, 0, 0, NULL);
  9637. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (833, 833, 'L_MENU_SUB_PROJECTS', '/user/projects/', 83, 1, 1, 1, 0, 0, NULL);
  9638. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (834, 834, 'L_MENU_PNAVIGATION', '/user/pnavigation/', 83, 2, 1, 1, 0, 0, NULL);
  9639. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (835, 835, 'L_MENU_PARCHIVE', '/user/archiveprojects/', 83, 3, 1, 1, 0, 0, NULL);
  9640. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (841, 841, 'L_MENU_SYSTEMOPTIONS', '/user/systemoptions/', 84, 1, 1, 1, 6, 0, NULL);
  9641. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (842, 842, 'L_MENU_DEPADMIN', '/user/createtree/', 84, 2, 1, 1, 3, 0, NULL);
  9642. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (843, 843, 'L_MENU_USERADMIN', '/user/createuser/', 84, 3, 1, 1, 3, 0, NULL);
  9643. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (844, 844, 'L_GLOBAL_USER_PROFILES', '/user/UserProfiles/', 84, 4, 1, 1, 6, 0, NULL);
  9644. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (845, 845, 'L_BOTS', '/user/bots/', 84, 5, 1, 1, 6, 0, NULL);
  9645. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (846, 846, 'L_MENU_GROUPRIGHTS', '/user/groupsrights/', 84, 6, 1, 1, 9, 0, NULL);
  9646. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (847, 847, 'L_MENU_USERRIGHTS', '/user/userrights/', 84, 7, 1, 1, 9, 0, NULL);
  9647. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (848, 848, 'L_MENU_PERM', '/user/permission/', 84, 8, 1, 1, 3, 0, NULL);
  9648. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (849, 849, 'L_MENU_ADMIN_MENUSETTINGS', '/user/menusettings/', 84, 9, 1, 1, 6, 0, NULL);
  9649. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (850, 850, 'L_MENU_ADMIN_TYPE_TASK', '/user/tasktypelist/', 84, 10, 1, 1, 16, 0, NULL);
  9650. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (851, 851, 'L_GLOBAL_TASK_COUNT', '/user/TaskCount', 84, 11, 1, 1, 16, 0, NULL);
  9651. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (852, 852, 'L_GLOBAL_MODEL_MESSAGE', '/user/MessageSettings/', 84, 12, 1, 0, 6, 0, NULL);
  9652. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (853, 853, 'L_MENU_ADMIN_NOTIFICATION_SETTINGS', '/user/notifsettings/', 84, 13, 1, 1, 6, 0, NULL);
  9653. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (854, 854, 'L_MENU_MAIL_SMS_TEST', '/user/mailtest', 84, 14, 1, 1, 6, 0, NULL);
  9654. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (855, 855, 'L_MENU_ADRESSBOOK_SETTINGS', '/user/setcontact', 84, 15, 1, 0, 6, 0, NULL);
  9655. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (856, 856, 'L_GLOBAL_WORK_CALENDAR', '/user/WorkCalendar/', 84, 16, 1, 1, 6, 0, NULL);
  9656. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (857, 857, 'L_MENU_ADMIN_DICTIONARY', '/user/admindict/', 84, 17, 1, 1, 21, 0, NULL);
  9657. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (858, 858, 'L_GLOBAL_PLUGINS', '/user/plugins', 84, 18, 1, 1, 6, 0, NULL);
  9658. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (859, 859, 'L_SEARCH_ADMIN', '/java/searchAdminPage', 84, 19, 1, 1, 6, 0, NULL);
  9659. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (860, 860, 'L_MENU_SISTEM_INFORMATION', '/user/sisteminfo', 84, 20, 1, 1, 6, 0, NULL);
  9660. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (861, 861, 'L_AU_DOC_CARDS', '/user/DocRegisterCards', 86, 1, 1, 1, 4, 0, 'docflow');
  9661. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (862, 862, 'L_MENU_ROUTESCHEME_EDITOR', '/user/rseditor', 86, 2, 1, 1, 4, 0, NULL);
  9662. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (863, 863, 'L_AU_DOCUMENT_COUNTERS', '/user/DocCount', 86, 3, 1, 1, 4, 0, 'docflow');
  9663. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (864, 864, 'L_GLOBAL_DICTIONARY_EDITOR', '/user/diction', 86, 4, 1, 1, 4, 0, NULL);
  9664. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (871, 871, 'L_GLOBAL_USE_STATISTIC', '/user/report_usestatistic', 87, 1, 1, 1, 5, 0, NULL);
  9665. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (872, 872, 'L_MENU_TRUST_POLICY', '/user/hostzones/', 87, 2, 1, 1, 5, 0, NULL);
  9666. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (873, 873, 'L_MENU_SECURITYREP5', '/user/securityrep5/', 87, 3, 1, 1, 5, 0, NULL);
  9667. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (874, 874, 'L_MENU_SECURITYREP4', '/user/securityrep4/', 87, 4, 1, 1, 5, 0, NULL);
  9668. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (875, 875, 'L_MENU_SECURITYREP3', '/user/securityrep3/', 87, 5, 1, 1, 5, 0, NULL);
  9669. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (876, 876, 'L_MENU_SECURITYREP2', '/user/securityrep2/', 87, 6, 1, 1, 5, 0, NULL);
  9670. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (877, 877, 'L_MENU_SECURITYREP1', '/user/securityrep1/', 87, 7, 1, 1, 5, 0, NULL);
  9671. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (878, 878, 'L_AU_LOG_TASKACCESSFORBIDDEN', '/user/prereport_selusers/taskaccessforbidden', 87, 8, 1, 1, 5, 0, NULL);
  9672. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (879, 879, 'L_MENU_SECURITYREP6', '/user/securityrep6/', 87, 9, 1, 0, 5, 0, 'docflow');
  9673. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (880, 880, 'L_MENU_DELETEDOCUMENTREPORT', '/user/selectdocumentprereport/deleted_documents/', 87, 10, 1, 1, 0, 0, 'docflow');
  9674. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (881, 881, 'L_MENU_REPORT_OUTERS_IN_LICENSE', '/user/prereport_outerusers', 87, 11, 1, 1, 6, 0, NULL);
  9675. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (882, 882, 'L_MENU_MYOPTIONS', '/user/pwd/', 88, 1, 1, 1, 0, 0, NULL);
  9676. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (883, 883, 'L_GLOBAL_MOTIWOPTIONS', '/user/pwd_settings/', 88, 2, 1, 1, 0, 0, NULL);
  9677. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (884, 884, 'L_MENU_MAILBOX_OPTIONS', '/user/mailboxoptions', 88, 3, 1, 1, 0, 0, NULL);
  9678. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (885, 885, 'L_MENU_MENUSETTINGS', '/user/menuedit/', 88, 4, 2, 1, 0, 0, NULL);
  9679. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (886, 886, 'L_MENU_SHADOWS', '/user/op_shadow/', 88, 5, 1, 1, 8, 0, NULL);
  9680. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (887, 887, 'L_MENU_NOTIFICATION_SETTINGS', '/user/pwd_notifprefs/', 88, 6, 1, 1, 0, 0, NULL);
  9681. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (888, 888, 'L_GLOBAL_COLOR_SETTINGS', '/user/pwd_colorprefs/', 88, 7, 1, 1, 0, 0, NULL);
  9682. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (889, 889, 'L_OPTIONS_DOCPREFS3', '/user/pwd_docprefs/', 88, 8, 1, 1, 0, 0, 'docflow');
  9683. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (890, 890, 'L_MENU_MYTEMPLATES', '/user/templateactions/', 88, 9, 1, 1, 0, 0, NULL);
  9684. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (891, 891, 'L_GLOBAL_EMAIL_EMPLOYER_GROUPS', '/user/outer_user_group_list', 88, 10, 1, 1, 0, 0, NULL);
  9685. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (892, 892, 'L_MENU_OUTER_USERS_EDIT', '/user/edit_outer_user/', 88, 11, 1, 1, 0, 0, NULL);
  9686. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (893, 893, 'L_MENU_TASK_TEMPLATES', '/user/tasktemplates', 88, 12, 1, 1, 0, 0, 'workflow');
  9687. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (894, 894, 'IWG_TEMPLATE', '/user/iwgtemplate', 88, 13, 1, 1, 0, 0, 'workflow');
  9688. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (895, 895, 'L_CHECKPOINTS_TEMPLATES', '/user/checkpoints_templates', 88, 14, 1, 1, 0, 0, NULL);
  9689. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (896, 896, 'L_MENU_DOCUMENTTEMPLATES', '/documents/documenttemplate', 88, 15, 1, 1, 1, 0, 'docflow');
  9690. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (951, 951, 'L_GENERAL_SEARCH', '/java/javasearch/', 95, 1, 1, 1, 0, 0, NULL);
  9691. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (952, 952, 'L_GLOBAL_TASK_SEARCH', '/user/searchtask', 95, 2, 1, 1, 0, 0, NULL);
  9692. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (953, 953, 'L_SEARCH_BY_TASK_NAME', '/user/searchbynum', 95, 3, 1, 1, 0, 0, NULL);
  9693. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (954, 954, 'L_SEARCHING_DOCUMENTS', '/documents/search/', 95, 4, 1, 1, 0, 0, 'docflow');
  9694. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (955, 955, 'L_SEARCH_BY_NOMER_DOCUMENT', '/user/searchdocbynum', 95, 5, 1, 1, 0, 0, 'docflow');
  9695. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (956, 956, 'L_SEARCH_BY_MES_NUM', '/user/searchbymesnum/', 95, 6, 1, 1, 0, 0, NULL);
  9696. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (501, 501, 'L_MENU_NEW_MESSAGE_ADD', '/user/unionsend/first', 50, 2, 1, 1, 0, 0, NULL);
  9697. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (502, 502, 'L_MENU_MESSAGE_ADD', '/user/noticeedit', 50, 3, 1, 1, 6, 0, NULL);
  9698. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (503, 503, 'L_MENU_UIONSENDEDIT', '/user/notices/', 50, 1, 1, 1, 0, 0, NULL);
  9699. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (901, 901, 'L_MENU_MANUAL', '/user/manuals', 90, 1, 1, 1, 0, 0, NULL);
  9700. INSERT INTO MENUITEMS (ID, ITEM_ID, DMESS_TAGNAME, URL, IDPARENT, NUMBER, ISVISIBLE, ISDEFVISIBLE, RIGHT_KIND, ID_EMPLOYER, EDITION) VALUES (902, 902, 'L_QUESTIONS_AND_ANSWERS', '/FAQ/index.phtml', 90, 2, 1, 1, 0, 0, NULL);
  9701. --копируем в пользователя -1
  9702. execute procedure copymenuitems (-1);
  9703. --копируем во всех неудаленных пользователей
  9704. for select e.id
  9705. from employer e
  9706. where e.isdeleted = 0
  9707. into :VAR_EMP
  9708. do
  9709. begin
  9710. execute procedure copymenuitems (:VAR_EMP);
  9711. end
  9712. end^
  9713.  
  9714. SET TERM ; ^
  9715. commit;
  9716.  
  9717. EXECUTE PROCEDURE MENUTRESH;
  9718. commit;
  9719. DROP PROCEDURE MENUTRESH;
  9720. commit;
  9721. update menuitems m set m.url = '/motiw4/Motiw4/Motiw4.html?sessionover=1' where m.dmess_tagname = 'L_MENU_IAP_ADMINISTRATION';
  9722. commit;
  9723. SET TERM ^ ;
  9724. CREATE OR ALTER PROCEDURE GET_FURIGHT_EMP_BY_DEP (
  9725. i_empid integer,
  9726. i_depid integer,
  9727. i_only_this_dep smallint)
  9728. returns (
  9729. o_empid integer)
  9730. as
  9731. declare variable l_flag smallint;
  9732. declare variable l_depid integer;
  9733. begin
  9734. /*возвращает людей, на которых есть ПОЛНЫЕ ПРАВА по подразделениям (с/без вложенных)*/
  9735. if (I_ONLY_THIS_DEP = 1) then
  9736. begin
  9737. for select id from employer e
  9738. join permission p on ( p.id_boss = :i_empid
  9739. and p.enabled = 1
  9740. and e.id = p.id_employer)
  9741. where e.id_department = :I_DEPID and
  9742. e.isdeleted = 0
  9743. into :O_EMPID
  9744. do
  9745. suspend;
  9746. end
  9747. else
  9748. for select gt.o_id from gettree (:I_DEPID, 0) gt
  9749. join deppermission dp on ( dp.id_department = gt.o_id
  9750. and id_employer = :i_empid
  9751. and enabled = 1 )
  9752.  
  9753. INTO :L_DEPID
  9754. do
  9755. begin
  9756. begin
  9757.  
  9758. for select id from employer e
  9759. join permission p on ( p.id_boss = :i_empid
  9760. and p.enabled = 1
  9761. and e.id = p.id_employer)
  9762. where e.id_department = :L_DEPID and
  9763. e.isdeleted = 0
  9764. into :O_EMPID
  9765. do
  9766. suspend;
  9767. end
  9768. end
  9769. END^
  9770.  
  9771. SET TERM ; ^
  9772. commit;
  9773. SET TERM ^ ;
  9774. CREATE OR ALTER PROCEDURE GETDOCUMENTS_REGISTRY (
  9775. i_id_employer integer,
  9776. i_id_department integer,
  9777. i_id_doctype integer,
  9778. i_only_thisdep smallint,
  9779. i_from_date timestamp,
  9780. i_to_date timestamp)
  9781. returns (
  9782. o_id_document integer,
  9783. o_createdate timestamp,
  9784. o_regdate timestamp,
  9785. o_state smallint,
  9786. o_taskid integer,
  9787. o_doc_version integer,
  9788. o_document_files varchar(30000))
  9789. as
  9790. declare variable l_rootdepid integer;
  9791. begin
  9792. /*возвращает идшники для расширеного реестра документов и еще всякую инфу*/
  9793. if (i_id_department is null) then
  9794. select id_department from employer where id = :i_id_employer
  9795. into :l_rootdepid;
  9796. else
  9797. l_rootdepid = :i_id_department;
  9798.  
  9799. begin
  9800.  
  9801. for select distinct d.id, (select first 1 g.id_task
  9802. from grouptask g
  9803. where g.task_id_document = d.id
  9804. and g.id_employer in
  9805. (select o_empid
  9806. from GET_FURIGHT_EMP_BY_DEP ( :i_id_employer , :l_rootdepid , :i_only_thisdep ) )
  9807. and g.task_id_document <>0
  9808. and g.task_state = 0)
  9809. from documents d
  9810. where d.isdeleted=0
  9811. and d.regdate >= :i_from_date
  9812. and d.regdate <= :i_to_date
  9813. and d.id_doctype = :I_ID_DOCTYPE
  9814. into :o_id_document,
  9815. :o_taskid
  9816.  
  9817. do
  9818. begin
  9819.  
  9820. select
  9821. d.createdate,
  9822. d.regdate,
  9823. d.state,
  9824. d.doc_version
  9825.  
  9826. from documents d
  9827. where d.id=:o_id_document
  9828.  
  9829. into
  9830.  
  9831. :o_createdate,
  9832. :o_regdate,
  9833. :o_state,
  9834. :o_doc_version;
  9835.  
  9836. select o_document_files from get_doc_files_list(:o_id_document,0)
  9837. into :o_document_files;
  9838. suspend;
  9839. end
  9840. end
  9841.  
  9842. END^
  9843.  
  9844. SET TERM ; ^
  9845. commit;
  9846.  
  9847.  
  9848. commit;
  9849. commit work;
  9850.  
  9851. Use CONNECT or CREATE DATABASE to specify a database
  9852. CONNECT "/var/Motiw/db/motiw.fdb" USER 'SYSDBA' PASSWORD 'masterkey';
  9853.  
  9854. SET NAMES WIN1251;
  9855.  
  9856. /*-------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  9857. /* Даем существующим пользователям право на тип задачи "Обычный" */
  9858. /*-------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  9859. SET TERM ^ ;
  9860. CREATE OR ALTER PROCEDURE TMP_SET_RIGHT_ON_USUAL
  9861. AS
  9862. declare variable l_id_employer integer;
  9863. BEGIN
  9864. FOR SELECT
  9865. id
  9866. FROM
  9867. employer
  9868. INTO
  9869. :l_id_employer
  9870. DO
  9871. BEGIN
  9872. EXECUTE PROCEDURE SET_RIGHT_EMPLOYER(:l_id_employer, 15, 0, 1);
  9873. END
  9874. END ^
  9875. SET TERM ; ^
  9876. commit;
  9877.  
  9878. EXECUTE PROCEDURE TMP_SET_RIGHT_ON_USUAL;
  9879. commit;
  9880. DROP PROCEDURE TMP_SET_RIGHT_ON_USUAL;
  9881. commit;
  9882.  
  9883. /*-------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  9884. /* Конвертация контрольных точек в подзадачи (начало) */
  9885. /*-------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  9886. SET TERM ^ ;
  9887. CREATE OR ALTER TRIGGER TASK_BI2 FOR TASK
  9888. ACTIVE BEFORE INSERT POSITION 2
  9889. AS
  9890. BEGIN
  9891. IF (NEW.ID IS NULL) THEN
  9892. NEW.ID = GEN_ID(GEN_TASK, 1);
  9893. IF (NEW.NUMERATOR IS NULL) THEN
  9894. NEW.NUMERATOR = NEW.ID;
  9895. END ^
  9896. SET TERM ; ^
  9897. commit;
  9898.  
  9899. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('TASK', 'TMP_ID_CHECKPOINT', 'INTEGER');
  9900.  
  9901. RESULT
  9902. =======
  9903. 1
  9904.  
  9905. commit;
  9906.  
  9907. SET TERM ^ ;
  9908. CREATE OR ALTER PROCEDURE TMP_DROP
  9909. AS
  9910. declare variable is_exist smallint;
  9911. BEGIN
  9912. SELECT result FROM IS_TRIGGER_EXISTS('TASK_BI2')
  9913. INTO :is_exist;
  9914.  
  9915. IF (is_exist = 1) THEN
  9916. begin
  9917. EXECUTE STATEMENT
  9918. 'DROP TRIGGER TASK_BI2;';
  9919. end
  9920.  
  9921. SELECT result FROM IS_FIELD_EXISTS('TASK', 'TMP_ID_CHECKPOINT')
  9922. INTO :is_exist;
  9923.  
  9924. IF (is_exist = 1) THEN
  9925. begin
  9926. EXECUTE STATEMENT
  9927. 'ALTER TABLE TASK DROP TMP_ID_CHECKPOINT;';
  9928. end
  9929.  
  9930. SELECT result FROM IS_TABLE_EXISTS('CHECKPOINTS')
  9931. INTO :is_exist;
  9932.  
  9933. IF (is_exist = 1) THEN
  9934. begin
  9935. EXECUTE STATEMENT
  9936. 'DROP GENERATOR GEN_CHECKPOINTS_ID;';
  9937. EXECUTE STATEMENT
  9938. 'DROP TRIGGER CHECKPOINTS_AU0;';
  9939. EXECUTE STATEMENT
  9940. 'DROP TRIGGER CHECKPOINTS_BU0;';
  9941. EXECUTE STATEMENT
  9942. 'DROP TRIGGER CHECKPOINTS_BI;';
  9943. EXECUTE STATEMENT
  9944. 'DROP TRIGGER CHECKPOINTS_BD0;';
  9945. EXECUTE STATEMENT
  9946. 'DROP TABLE CHECKPOINTS;';
  9947. end
  9948. END ^
  9949. SET TERM ; ^
  9950. commit;
  9951.  
  9952. EXECUTE PROCEDURE ADD_FIELD_IF_DOES_NOT_EXIST('TASK', 'IS_CHECKPOINT', 'SMALLINT');
  9953.  
  9954. RESULT
  9955. =======
  9956. 1
  9957.  
  9958. commit;
  9959.  
  9960. EXECUTE PROCEDURE ADD_INDEX_IF_DOES_NOT_EXIST('NOTICE_IDX_ID_OBJ', 'NOTICE', 'ID_OBJ');
  9961.  
  9962. RESULT
  9963. =======
  9964. 1
  9965.  
  9966. commit;
  9967.  
  9968. SET TERM ^ ;
  9969. CREATE OR ALTER PROCEDURE TMP_CHECKPOINTS_2_SUBTASKS
  9970. AS
  9971. BEGIN
  9972.  
  9973. INSERT INTO task (name,
  9974. startdate,
  9975. enddate,
  9976. iswithreport,
  9977. state,
  9978. priority,
  9979. description,
  9980. id_project,
  9981. send_actions,
  9982. parentid,
  9983. id_realauthor,
  9984. id_taskinitiator,
  9985. tsreport,
  9986. id_meta_dictionary,
  9987. id_department,
  9988. tmp_id_checkpoint,
  9989. is_checkpoint)
  9990. SELECT
  9991. chp.name,
  9992. chp.enddate,
  9993. chp.enddate,
  9994. 0,
  9995. chp.state,
  9996. 0,
  9997. chp.description,
  9998. (SELECT t1.id_project FROM task t1 WHERE t1.id = chp.id_task),
  9999. 1,
  10000. chp.id_task,
  10001. (SELECT t1.id_realauthor FROM task t1 WHERE t1.id = chp.id_task),
  10002. (SELECT t1.id_taskinitiator FROM task t1 WHERE t1.id = chp.id_task),
  10003. chp.readydate,
  10004. 0,
  10005. (SELECT t1.id_department FROM task t1 WHERE t1.id = chp.id_task),
  10006. chp.id,
  10007. 1
  10008. FROM checkpoints chp;
  10009.  
  10010.  
  10011. UPDATE notice n
  10012. SET n.id_obj = (SELECT t.id FROM task t
  10013. WHERE t.tmp_id_checkpoint = n.id_obj)
  10014. WHERE n.noticetype = 5;
  10015.  
  10016. END ^
  10017. SET TERM ; ^
  10018. commit;
  10019.  
  10020. EXECUTE PROCEDURE TMP_CHECKPOINTS_2_SUBTASKS;
  10021. commit;
  10022. DROP PROCEDURE TMP_CHECKPOINTS_2_SUBTASKS;
  10023. commit;
  10024.  
  10025. SET TERM ^ ;
  10026.  
  10027. CREATE OR ALTER PROCEDURE CALENDARREPORT (
  10028. i_employer_id integer)
  10029. returns (
  10030. o_projectname varchar(2000),
  10031. o_proj_id integer,
  10032. o_taskid integer,
  10033. o_taskname varchar(2000),
  10034. o_startdate timestamp,
  10035. o_enddate timestamp,
  10036. o_isreported smallint,
  10037. o_isrejected smallint,
  10038. o_isgroup smallint,
  10039. o_isviewed smallint,
  10040. o_adate timestamp,
  10041. o_documentid integer,
  10042. o_ishidden smallint,
  10043. o_istrashproject smallint,
  10044. o_isnewactions smallint,
  10045. o_pdocumentid integer,
  10046. o_taskcolor smallint,
  10047. o_doctypename varchar(200),
  10048. o_why_task_there smallint,
  10049. o_entity_end_date timestamp,
  10050. o_id_entity integer,
  10051. o_entity_text varchar(2000))
  10052. as
  10053. declare variable l_originalid integer;
  10054. declare variable l_taskexist_result smallint;
  10055. begin
  10056. select e.parentid
  10057. from employer e
  10058. where e.id=:i_employer_id
  10059. into :L_ORIGINALID;
  10060. if (:L_ORIGINALID is null) then
  10061. L_ORIGINALID=:i_employer_id;
  10062. for select t.id, 1, t.enddate
  10063. from task t
  10064. join grouptask gt on t.id = gt.id_task
  10065. where t.state = 0 and
  10066. t.isdeleted = 0 and
  10067. gt.id_original = :i_employer_id and
  10068. (gt.is_author = 1 or gt.is_respperson = 1 or
  10069. gt.is_worker = 1 or gt.is_shadow = 1)
  10070. into :o_taskid,:o_why_task_there,:o_entity_end_date
  10071. DO
  10072. BEGIN
  10073. select o_id,
  10074. O_PROJECTNAME,
  10075. O_TASKNAME,
  10076. O_STARTDATE,
  10077. O_ENDDATE,
  10078. O_ISREPORTED,
  10079. O_ISREJECTED,
  10080. O_PROJ_ID,
  10081. O_ISGROUP,
  10082. O_ISVIEWED,
  10083. O_ADATE,
  10084. O_DOCUMENTID,
  10085. O_ISHIDDEN,
  10086. O_ISTRASHPROJECT,
  10087. O_ISNEWACTIONS,
  10088. O_PDOCUMENTID,
  10089. O_TASKCOLOR,
  10090. O_DOCTYPENAME,
  10091. O_MAIN_RESULT
  10092. from gettaskattributes_for_calendar(:O_TASKID, :L_ORIGINALID)
  10093. into :o_taskid,
  10094. :O_PROJECTNAME,
  10095. :O_TASKNAME,
  10096. :O_STARTDATE,
  10097. :O_ENDDATE,
  10098. :O_ISREPORTED,
  10099. :O_ISREJECTED,
  10100. :O_PROJ_ID,
  10101. :O_ISGROUP,
  10102. :O_ISVIEWED,
  10103. :O_ADATE,
  10104. :O_DOCUMENTID,
  10105. :O_ISHIDDEN,
  10106. :O_ISTRASHPROJECT,
  10107. :O_ISNEWACTIONS,
  10108. :O_PDOCUMENTID,
  10109. :O_TASKCOLOR,
  10110. :O_DOCTYPENAME,
  10111. :L_TASKEXIST_RESULT;
  10112. if (:L_TASKEXIST_RESULT=1) then
  10113. begin
  10114. o_entity_text=null;o_id_entity=null;
  10115. suspend;
  10116. if (O_ISHIDDEN=1) then
  10117. begin
  10118. /* for SELECT 2,ht.showdate
  10119. FROM hiddentasks ht
  10120. WHERE ht.id_task=:o_taskid and ht.id_employer=:l_originalid
  10121. INTO :O_WHY_TASK_THERE,:o_entity_end_date
  10122. do suspend;
  10123. */
  10124. for select 2,gt.show_task_date
  10125. FROM grouptask gt
  10126. WHERE gt.id_task=:o_taskid and gt.id_original=:l_originalid
  10127. INTO :O_WHY_TASK_THERE,:o_entity_end_date
  10128. do suspend;
  10129. end
  10130. for SELECT 4, cp.enddate, cp.description, cp.id
  10131. FROM task cp
  10132. WHERE cp.is_checkpoint = 1 and cp.parentid = :o_taskid and cp.state = 0
  10133. INTO :O_WHY_TASK_THERE,:o_entity_end_date,:o_entity_text,:o_id_entity
  10134. do suspend;
  10135. end
  10136. END
  10137. if (:L_ORIGINALID = :i_employer_id) then
  10138. begin
  10139. FOR SELECT n1.id_task,3,n1.meetingtime,n1.name||'{L_SENDMR_PLACE}'||n1.place||'{L_GLOBAL_ADDINFO}'||n1.description,n1.id
  10140. FROM notice n1,
  10141. noticeview nv,
  10142. task t3
  10143. WHERE nv.id_employer = :i_employer_id and
  10144. nv.id_notice=n1.id and
  10145. n1.isdeleted=0 and
  10146. n1.id_task=t3.id and
  10147. t3.state = 0 and
  10148. t3.isdeleted = 0 and
  10149. n1.noticetype=3
  10150. INTO :O_TASKID,:O_WHY_TASK_THERE,:o_entity_end_date,:o_entity_text,:o_id_entity
  10151. DO
  10152. BEGIN
  10153. select o_id,
  10154. O_PROJECTNAME,
  10155. O_TASKNAME,
  10156. O_STARTDATE,
  10157. O_ENDDATE,
  10158. O_ISREPORTED,
  10159. O_ISREJECTED,
  10160. O_PROJ_ID,
  10161. O_ISGROUP,
  10162. O_ISVIEWED,
  10163. O_ADATE,
  10164. O_DOCUMENTID,
  10165. O_ISHIDDEN,
  10166. O_ISTRASHPROJECT,
  10167. O_ISNEWACTIONS,
  10168. O_PDOCUMENTID,
  10169. O_TASKCOLOR,
  10170. O_DOCTYPENAME,
  10171. O_MAIN_RESULT
  10172. from gettaskattributes_for_calendar(:O_TASKID, :L_ORIGINALID)
  10173. into :o_taskid,
  10174. :O_PROJECTNAME,
  10175. :O_TASKNAME,
  10176. :O_STARTDATE,
  10177. :O_ENDDATE,
  10178. :O_ISREPORTED,
  10179. :O_ISREJECTED,
  10180. :O_PROJ_ID,
  10181. :O_ISGROUP,
  10182. :O_ISVIEWED,
  10183. :O_ADATE,
  10184. :O_DOCUMENTID,
  10185. :O_ISHIDDEN,
  10186. :O_ISTRASHPROJECT,
  10187. :O_ISNEWACTIONS,
  10188. :O_PDOCUMENTID,
  10189. :O_TASKCOLOR,
  10190. :O_DOCTYPENAME,
  10191. :L_TASKEXIST_RESULT;
  10192. if (:L_TASKEXIST_RESULT=1) then suspend;
  10193. END
  10194. FOR SELECT n1.id_task,5,nv.showdate,n1.name||'{L_GLOBAL_ADDINFO}'||n1.description,n1.id
  10195. FROM notice n1,
  10196. noticeview nv,
  10197. task t3
  10198. WHERE nv.id_employer = :i_employer_id and
  10199. nv.id_notice=n1.id and
  10200. n1.isdeleted=0 and
  10201. n1.id_task=t3.id and
  10202. t3.state = 0 and
  10203. t3.isdeleted = 0 and
  10204. n1.noticetype=6 and
  10205. n1.isshowtasklink=1
  10206. INTO :O_TASKID,:O_WHY_TASK_THERE,:o_entity_end_date,:o_entity_text,:o_id_entity
  10207. DO
  10208. BEGIN
  10209. select o_id,
  10210. O_PROJECTNAME,
  10211. O_TASKNAME,
  10212. O_STARTDATE,
  10213. O_ENDDATE,
  10214. O_ISREPORTED,
  10215. O_ISREJECTED,
  10216. O_PROJ_ID,
  10217. O_ISGROUP,
  10218. O_ISVIEWED,
  10219. O_ADATE,
  10220. O_DOCUMENTID,
  10221. O_ISHIDDEN,
  10222. O_ISTRASHPROJECT,
  10223. O_ISNEWACTIONS,
  10224. O_PDOCUMENTID,
  10225. O_TASKCOLOR,
  10226. O_DOCTYPENAME,
  10227. O_MAIN_RESULT
  10228. from gettaskattributes_for_calendar(:O_TASKID, :L_ORIGINALID)
  10229. into :o_taskid,
  10230. :O_PROJECTNAME,
  10231. :O_TASKNAME,
  10232. :O_STARTDATE,
  10233. :O_ENDDATE,
  10234. :O_ISREPORTED,
  10235. :O_ISREJECTED,
  10236. :O_PROJ_ID,
  10237. :O_ISGROUP,
  10238. :O_ISVIEWED,
  10239. :O_ADATE,
  10240. :O_DOCUMENTID,
  10241. :O_ISHIDDEN,
  10242. :O_ISTRASHPROJECT,
  10243. :O_ISNEWACTIONS,
  10244. :O_PDOCUMENTID,
  10245. :O_TASKCOLOR,
  10246. :O_DOCTYPENAME,
  10247. :L_TASKEXIST_RESULT;
  10248. if (:L_TASKEXIST_RESULT=1) then suspend;
  10249. END
  10250. end
  10251. end^
  10252.  
  10253. SET TERM ; ^
  10254. commit;
  10255.  
  10256. /* Переносим триггеры из checkpoints в task*/
  10257. SET TERM ^ ;
  10258.  
  10259. CREATE OR ALTER TRIGGER TASK_AU01 FOR TASK
  10260. ACTIVE AFTER UPDATE POSITION 0
  10261. AS
  10262. begin
  10263. if (new.parentid > 0) then
  10264. begin
  10265. if (old.state = 0 and new.state = 1) then
  10266. begin
  10267. update notice n set n.isdeleted = 1
  10268. where n.noticetype = 5 and n.obj_kind = 1 and n.id_obj = old.id and n.id_task = old.parentid;
  10269.  
  10270. delete from noticeview nv
  10271. where nv.id_notice in (select n.id from notice n
  10272. where n.noticetype = 5 and n.obj_kind = 1 and n.id_obj = old.id and n.id_task = old.parentid and n.isdeleted = 1);
  10273. end
  10274. else
  10275. if (old.enddate <> new.enddate) then
  10276. begin
  10277. update notice n set n.showdate = n.showdate + (new.enddate - old.enddate)
  10278. where n.noticetype = 5 and n.obj_kind = 1 and n.id_obj = old.id and n.id_task = old.parentid and n.isdeleted = 0;
  10279.  
  10280. update noticeview nv set nv.showdate = nv.showdate + (new.enddate - old.enddate)
  10281. where nv.id_notice in (select n.id from notice n
  10282. where n.noticetype = 5 and n.obj_kind = 1 and n.id_obj = old.id and n.id_task = old.parentid and n.isdeleted = 0);
  10283. end
  10284. end
  10285. end^
  10286.  
  10287. SET TERM ; ^
  10288. commit;
  10289.  
  10290. SET TERM ^ ;
  10291.  
  10292. CREATE OR ALTER TRIGGER TASK_AD0 FOR TASK
  10293. ACTIVE AFTER DELETE POSITION 0
  10294. AS
  10295. DECLARE VARIABLE L_N_ID INTEGER;
  10296. begin
  10297. for select n.id
  10298. from notice n
  10299. where n.noticetype=5 and
  10300. n.obj_kind=1 and
  10301. n.id_obj=old.id and
  10302. n.id_task=old.parentid
  10303. into :L_N_ID
  10304. do
  10305. begin
  10306. delete from noticeview nv where nv.id_notice=:L_N_ID;
  10307. delete from notice n2 where n2.id=:L_N_ID;
  10308. end
  10309. end^
  10310.  
  10311. SET TERM ; ^
  10312. commit;
  10313.  
  10314. EXECUTE PROCEDURE TMP_DROP;
  10315. Statement failed, SQLCODE = -607
  10316. unsuccessful metadata update
  10317. -Trigger CHECKPOINTS_BU0 not found
  10318. -At procedure 'TMP_DROP' line: 32, col: 13
  10319. After line 888 in file /tmp/patch_db/script
  10320. DROP PROCEDURE TMP_DROP;
  10321. commit;
  10322. /*-------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  10323. /* Конвертация контрольных точек в подзадачи (окончание) */
  10324. /*-------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  10325.  
  10326. /*-------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  10327. /* Позволяем Ответственному Руководителю редактировать задачу */
  10328. /*-------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  10329. SET TERM ^ ;
  10330. ALTER PROCEDURE CHECKTASKEDIT (
  10331. I_ID_EMPLOYER Integer,
  10332. I_ID_TASK Integer )
  10333. RETURNS (
  10334. O_RESULT Smallint )
  10335. AS
  10336. DECLARE VARIABLE L_SUPERVISOR SMALLINT;
  10337. DECLARE VARIABLE L_AUTHOR_ID INTEGER;
  10338. DECLARE VARIABLE L_COUNT INTEGER;
  10339. begin
  10340. /* Проверяет может ли пользователь редактировать аттрибуты задачи. Это название, описание, приоритет и т. п.
  10341. * В общем все то, что редактируется при заходе в задачу, в шапке задачи маленькими картиночками справа.
  10342. * Редактировать может либо автор, либо администратор системы, а теперь и ответственный руководитель.
  10343. */
  10344.  
  10345. /* Проверяем автора или ответственного руководителя */
  10346. if (exists(select gt.id_task
  10347. from grouptask gt
  10348. where gt.id_task = :I_ID_TASK and
  10349. gt.id_original = :I_ID_EMPLOYER and
  10350. (gt.is_author = 1 or gt.is_respperson = 1))) then
  10351. begin
  10352. o_result = 1;
  10353. suspend;
  10354. exit;
  10355. end
  10356. /* Проверяем не администратор ли системы */
  10357. select o_result
  10358. from get_right_employer_and_group(:i_id_employer,6,0)
  10359. into :l_supervisor;
  10360.  
  10361. if (l_supervisor > 0) then
  10362. begin
  10363. o_result = 1;
  10364. suspend;
  10365. exit;
  10366. end
  10367. o_result = 0;
  10368. suspend;
  10369. end^
  10370. SET TERM ; ^
  10371. commit;
  10372.  
  10373. GRANT EXECUTE
  10374. ON PROCEDURE CHECKTASKEDIT TO ROLE COMMON;
  10375.  
  10376. GRANT EXECUTE
  10377. ON PROCEDURE CHECKTASKEDIT TO TRIGGER DEPARTMENT_BU0;
  10378.  
  10379. GRANT EXECUTE
  10380. ON PROCEDURE CHECKTASKEDIT TO TRIGGER EMPLOYER_AI0;
  10381.  
  10382. GRANT EXECUTE
  10383. ON PROCEDURE CHECKTASKEDIT TO TRIGGER EMPLOYER_AU0;
  10384.  
  10385. GRANT EXECUTE
  10386. ON PROCEDURE CHECKTASKEDIT TO TRIGGER GROUPTASK_AD0;
  10387.  
  10388. GRANT EXECUTE
  10389. ON PROCEDURE CHECKTASKEDIT TO TRIGGER GROUPTASK_AI0;
  10390.  
  10391. GRANT EXECUTE
  10392. ON PROCEDURE CHECKTASKEDIT TO SYSDBA;
  10393.  
  10394. GRANT EXECUTE
  10395. ON PROCEDURE CHECKTASKEDIT TO TRIGGER TASK_AU0;
  10396. commit;
  10397. /*-------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  10398. /* Позволяем Ответственному Руководителю редактировать задачу (окончание) */
  10399. /*-------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  10400.  
  10401. /*-------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  10402. /* Переиндексация */
  10403. /*-------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  10404.  
  10405. /* reindexTasks */
  10406. DELETE FROM queue_indexing WHERE object_kind = 2;
  10407. INSERT INTO queue_indexing(id_object, object_kind, event_code) SELECT t.id, 2, 1 FROM task t WHERE t.isdeleted = 0;
  10408.  
  10409. /* reindexActions */
  10410. DELETE FROM queue_indexing WHERE object_kind = 1;
  10411. INSERT INTO queue_indexing(id_object, object_kind, event_code) SELECT a.id, 1, 1 FROM actions a JOIN task t ON a.id_task = t.id WHERE t.isdeleted = 0;
  10412.  
  10413. /* reindexDocuments */
  10414. DELETE FROM queue_indexing WHERE object_kind = 3;
  10415. INSERT INTO queue_indexing(id_object, object_kind, event_code) SELECT d.id, 3, 1 FROM documents d WHERE d.isdeleted = 0;
  10416.  
  10417. /* reindexTaskFiles */
  10418. DELETE FROM queue_indexing WHERE object_kind = 5;
  10419. INSERT INTO queue_indexing(id_object, object_kind, event_code) SELECT att.id, 5, 1 FROM attachment att WHERE att.isdeleted = 0;
  10420.  
  10421. /* reindexDocumentFiles */
  10422. DELETE FROM queue_indexing WHERE object_kind = 7;
  10423. INSERT INTO queue_indexing(id_object, object_kind, event_code) SELECT da.id, 7, 1 FROM documentattachment da WHERE da.isdeleted = 0;
  10424.  
  10425. /* reindexDocumentLibrary */
  10426. DELETE FROM queue_indexing WHERE object_kind = 9;
  10427. INSERT INTO queue_indexing(id_object, object_kind, event_code) SELECT dlf.id, 9, 1 FROM dlfile dlf WHERE dlf.isdeleted = 0;
  10428.  
  10429. /* reindexEmployers */
  10430. DELETE FROM queue_indexing WHERE object_kind = 10;
  10431. INSERT INTO queue_indexing(id_object, object_kind, event_code) SELECT e.id, 10, 1 FROM employer e WHERE e.isdeleted = 0;
  10432.  
  10433. /* reindexContacts */
  10434. DELETE FROM queue_indexing WHERE object_kind = 11;
  10435. INSERT INTO queue_indexing(id_object, object_kind, event_code)
  10436. SELECT distinct mv.id_record, 11, 1
  10437. FROM meta_dictionary md
  10438. JOIN meta_field mf ON md.id = mf.id_md
  10439. JOIN meta_value mv ON mf.id = mv.id_mf
  10440. WHERE (md.issystem = 2 and md.isdeleted = 0 and mv.isdeleted = 0);
  10441.  
  10442. /* reindexProjects */
  10443. DELETE FROM queue_indexing WHERE object_kind = 12;
  10444. INSERT INTO queue_indexing(id_object, object_kind, event_code) SELECT distinct ID, 12, 1 FROM PROJECT;
  10445.  
  10446. commit;
  10447.  
  10448. /*-------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  10449. /* Для полей-ссылок заполняем value_varchar отображаемым значением */
  10450. /*-------------------------------------------------------------------------------------------------------------------------------------------------------------*/
  10451. UPDATE
  10452. meta_value mv
  10453. SET
  10454. mv.value_varchar = (SELECT FIRST 1
  10455. CASE
  10456. WHEN mf2.id_type_field in (1, 7, 10, 11, 12, 13) THEN mv1.value_char
  10457. WHEN mf2.id_type_field = 5 THEN mv1.value_date
  10458. WHEN mf2.id_type_field = 4 THEN mv1.value_float
  10459. WHEN mf2.id_type_field in (3, 6, 14, 16, 17) THEN mv1.value_integer
  10460. WHEN mf2.id_type_field in (2, 8, 9, 18) THEN mv1.value_varchar
  10461. ELSE null
  10462. END
  10463. FROM
  10464. meta_value mv1
  10465. JOIN
  10466. meta_field mf1 ON mf1.id = mv.id_mf
  10467. JOIN
  10468. meta_field mf2 ON mf2.id = mf1.id_connect
  10469. WHERE
  10470. mv1.id_record = mv.value_integer AND
  10471. mv1.id_mf = mf1.id_connect AND
  10472. mv1.isdeleted = 0)
  10473. WHERE
  10474. mv.isdeleted = 0 AND
  10475. mv.id_mf in (SELECT
  10476. mf.id
  10477. FROM
  10478. meta_field mf
  10479. WHERE
  10480. mf.id_type_field in (8, 9) AND
  10481. mf.isdeleted = 0
  10482. );
  10483. commit;
  10484.  
  10485. /*stasy - избавляемся от "избранного"*/
  10486. /*сначала заменим во всех процедурах где исспользуется*/
  10487. /*GETALLTASKRIGHTS*/
  10488. SET TERM ^ ;
  10489. CREATE OR ALTER PROCEDURE GETALLTASKRIGHTS (
  10490. i_myid integer,
  10491. i_taskid integer)
  10492. returns (
  10493. o_isrights smallint,
  10494. o_isgroup smallint,
  10495. o_isauthor smallint,
  10496. o_isemployer smallint,
  10497. o_isclosed smallint,
  10498. o_isonlyforview smallint,
  10499. o_parentid integer,
  10500. o_documentid integer,
  10501. o_pdocumentid integer,
  10502. o_isreported smallint,
  10503. o_isdeleted integer,
  10504. o_isingroup smallint,
  10505. o_isinsignlist smallint,
  10506. o_taskexamined smallint,
  10507. o_taskfolderid integer,
  10508. o_recive_sms smallint,
  10509. o_recive_mail smallint,
  10510. o_taskid integer,
  10511. o_iscontroller smallint)
  10512. as
  10513. begin
  10514. /* Параметр O_TASKID нужен для проверки того, что проца действительно вернула данные, а не отвалилась
  10515. Для режима высокой нагрузки.
  10516. */
  10517. O_TASKID = 0;
  10518. execute procedure checkrightsfortask(:i_myid,:i_taskid)
  10519. returning_values :o_isrights;
  10520. select t.state,
  10521. t.isreported,
  10522. t.isgroup,
  10523. t.isonlyforview,
  10524. t.parentid,
  10525. t.id_document,
  10526. t.isdeleted,
  10527. t.id_document_exec
  10528. from task t
  10529. where t.id=:i_taskid
  10530. into :o_isclosed,
  10531. :o_isreported,
  10532. :o_isgroup,
  10533. :o_isonlyforview,
  10534. :o_parentid,
  10535. :o_documentid,
  10536. :o_isdeleted,
  10537. :o_pdocumentid;
  10538.  
  10539. if (exists (select id_employer
  10540. from grouptask gt
  10541. where gt.id_original=:i_myid and
  10542. gt.id_task=:i_taskid and
  10543. gt.is_author=1) ) then o_isauthor=1;
  10544. else o_isauthor=0;
  10545.  
  10546. if (exists (select id_employer
  10547. from grouptask gt
  10548. where gt.id_original=:i_myid and
  10549. gt.id_task=:i_taskid and
  10550. gt.is_respperson=1) ) then o_isemployer=1;
  10551. else o_isemployer=0;
  10552.  
  10553. o_isingroup=0;
  10554. if (o_isgroup=1) then /*Проверяем находится ли емплоер в группе*/
  10555. begin
  10556. if (exists (select gt.id_employer
  10557. from grouptask gt
  10558. where gt.id_task=:i_taskid and
  10559. gt.id_original=:i_myid and
  10560. (gt.is_worker=1 or gt.is_shadow=1))) then
  10561. o_isingroup=1;
  10562. end
  10563. o_iscontroller=0;
  10564. if (exists (select gt.id_employer
  10565. from grouptask gt
  10566. where gt.id_task=:i_taskid and
  10567. gt.id_original=:i_myid and
  10568. (gt.is_controler=1))) then
  10569. o_iscontroller=1;
  10570.  
  10571. o_isinsignlist = 0;
  10572. if (o_documentid>0) then
  10573. begin
  10574. if (exists(select rn.id_employer from routetrees rt
  10575. join routenode rn on rt.id = rn.id_routetree
  10576. where (rt.id_task = :i_taskid)and(rt.isdeleted=0)and
  10577. (rn.id_employer = :i_myid)and(rn.isdeleted=0)
  10578. )) then
  10579. o_isinsignlist = 1;
  10580. else
  10581. if (exists(select rn.id_employer from routetrees rt
  10582. join routenode rn on rt.id = rn.id_routetree
  10583. join getemployeraliases(:i_myid) gea on gea.o_employerid = rn.id_employer
  10584. where (rt.id_task = :i_taskid)and(rt.isdeleted=0)and(rn.isdeleted=0)
  10585. )) then
  10586. o_isinsignlist = 1;
  10587.  
  10588. end
  10589.  
  10590. o_taskexamined=0;
  10591. if (o_isonlyforview=1) then
  10592. begin
  10593. if (exists(select id
  10594. from actions
  10595. where id_employer = :i_myid and
  10596. id_task = :i_taskid and
  10597. examinated is not null and
  10598. examinated > 0
  10599. )
  10600. ) then
  10601. o_taskexamined=1;
  10602. end
  10603.  
  10604.  
  10605. if (:o_taskfolderid is null) then
  10606. o_taskfolderid=0;
  10607.  
  10608.  
  10609. select gtms.o_recive_sms,
  10610. gtms.o_recive_mail
  10611. from get_task_mail_sms(:i_taskid,:i_myid) gtms
  10612. into :o_recive_sms,
  10613. :o_recive_mail;
  10614. O_TASKID = :i_taskid;
  10615. suspend;
  10616. end^
  10617. SET TERM ; ^
  10618. commit;
  10619.  
  10620. /*GET_TASK_ATTRIBUTES_AS_NUM*/
  10621. SET TERM ^ ;
  10622. CREATE OR ALTER PROCEDURE GET_TASK_ATTRIBUTES_AS_NUM (
  10623. i_id_task integer,
  10624. i_id_employer integer)
  10625. returns (
  10626. o_value smallint)
  10627. as
  10628. declare variable l_priority smallint;
  10629. declare variable l_is_secret smallint;
  10630. declare variable l_is_olnly_for_view smallint;
  10631. declare variable l_enddate timestamp;
  10632. begin
  10633. /*
  10634. 1 - Скрытая задача
  10635. 2 - В избранном
  10636. 3 - Важная
  10637. 5 - Для ознакомления
  10638. 6 - Просроченная
  10639. 7 - Секретная
  10640. 8- обычная задача
  10641. */
  10642. o_value=8;
  10643. if (exists(select ht.id_task from hiddentasks ht
  10644. where ht.id_employer=:i_id_employer and ht.id_task=:i_id_task)) then
  10645. begin
  10646. o_value=1;
  10647. suspend;
  10648. end
  10649.  
  10650. select t.priority,t.issecret,t.isonlyforview,t.enddate from task t
  10651. where t.id = :i_id_task
  10652. into :l_priority,:l_is_secret,:l_is_olnly_for_view,:l_enddate;
  10653. if (:l_priority=1) then
  10654. begin
  10655. o_value=3;
  10656. suspend;
  10657. end
  10658. if (:l_is_olnly_for_view=1) then
  10659. begin
  10660. o_value=5;
  10661. suspend;
  10662. end
  10663. if ((:l_enddate<current_timestamp)) then
  10664. begin
  10665. o_value=6;
  10666. suspend;
  10667. end
  10668. if (:l_is_secret=1) then
  10669. begin
  10670. o_value=7;
  10671. suspend;
  10672. end
  10673. if (:o_value=8) then suspend;
  10674.  
  10675. end^
  10676. SET TERM ; ^
  10677. commit;
  10678.  
  10679. /*GET_TASK_USERS_TO_NOTIFY*/
  10680. SET TERM ^ ;
  10681. CREATE OR ALTER PROCEDURE GET_TASK_USERS_TO_NOTIFY (
  10682. i_task_id integer,
  10683. isonlyforview smallint,
  10684. id_document integer)
  10685. returns (
  10686. o_id_employer integer,
  10687. o_status integer)
  10688. as
  10689. declare variable l_emp_id integer;
  10690. declare variable l_res1 smallint;
  10691. declare variable l_res2 smallint;
  10692. begin
  10693. for select gt.id_original as eid,0
  10694. from grouptask gt
  10695. where gt.id_task = :i_task_id and
  10696. (gt.is_author = 1 or gt.is_respperson = 1 or gt.is_worker = 1 or gt.is_controler=1 or gt.is_shadow=1 ) and
  10697. gt.is_show_task = 1
  10698. into :O_ID_EMPLOYER,:o_status
  10699. do
  10700. suspend;
  10701.  
  10702. end^
  10703. SET TERM ; ^
  10704. commit;
  10705.  
  10706. /*INFORMER2_CHECKRIGHTSFORTASK*/
  10707. SET TERM ^ ;
  10708. CREATE OR ALTER PROCEDURE INFORMER2_CHECKRIGHTSFORTASK (
  10709. i_myid integer,
  10710. i_taskid integer)
  10711. returns (
  10712. o_result smallint)
  10713. as
  10714. declare variable l_isgroup smallint;
  10715. declare variable l_result smallint;
  10716. declare variable l_employerid integer;
  10717. declare variable l_employerid2 integer;
  10718. declare variable l_taskauthorid integer;
  10719. declare variable l_taskemployerid integer;
  10720. begin
  10721. /* Проверка, имеет ли пользователь права на задачу */
  10722. O_RESULT=0;
  10723.  
  10724. if (exists(select id_task from grouptask g where g.id_task=:i_taskid and g.id_employer=:i_myid)) then
  10725. begin
  10726. O_RESULT = 1;
  10727. suspend;
  10728. exit;
  10729. end
  10730.  
  10731. if (O_RESULT = 0) then
  10732. for select o_employerid
  10733. from getemployeraliases(:i_myid)
  10734. into :l_employerid2
  10735. do
  10736. begin
  10737. select O_RESULT
  10738. from INFORMER2_CHECKRIGHTSFORTASK(:l_employerid2, :i_taskid)
  10739. into :O_RESULT;
  10740.  
  10741. if (O_RESULT = 1) then
  10742. begin
  10743. suspend;
  10744. exit;
  10745. end
  10746. end
  10747.  
  10748. O_RESULT = 0;
  10749. suspend;
  10750. end^
  10751. SET TERM ; ^
  10752. commit;
  10753.  
  10754. /*INFORMER2_GETMYTASKS*/
  10755. SET TERM ^ ;
  10756. CREATE OR ALTER PROCEDURE INFORMER2_GETMYTASKS (
  10757. id_employer integer,
  10758. ataskid integer,
  10759. mintaskid integer)
  10760. returns (
  10761. taskid integer,
  10762. taskname varchar(2000),
  10763. isviewed smallint,
  10764. isgroup smallint,
  10765. isnewmessages smallint,
  10766. amiauthor smallint,
  10767. prjid integer,
  10768. isreported smallint,
  10769. authorid integer,
  10770. empid integer,
  10771. isrejected smallint,
  10772. iswithreport smallint,
  10773. lastactid integer,
  10774. taskdesc varchar(10000),
  10775. startdate timestamp,
  10776. enddate timestamp,
  10777. actcount integer,
  10778. att varchar(24000),
  10779. task_type smallint,
  10780. ordertype smallint,
  10781. documentid integer,
  10782. priority smallint,
  10783. lastactdate timestamp,
  10784. empsid varchar(5000),
  10785. deppath varchar(2000),
  10786. state smallint,
  10787. lastact varchar(10000),
  10788. lastactempid integer,
  10789. isonlyforview smallint,
  10790. userid integer,
  10791. mycolor smallint,
  10792. send_actions smallint,
  10793. receive_mail smallint,
  10794. receive_sms smallint,
  10795. acount integer,
  10796. lastacount integer,
  10797. documentname varchar(1000),
  10798. documenttypeid integer,
  10799. isresolution smallint,
  10800. id_realauthor integer,
  10801. id_taskinitiator integer,
  10802. docversion integer,
  10803. btn varchar(200),
  10804. parentid integer,
  10805. showdate timestamp,
  10806. idfolder integer,
  10807. issecretary smallint,
  10808. iscontrol smallint,
  10809. ctrlsid varchar(2000),
  10810. signsid varchar(2000),
  10811. is_have_isolated smallint,
  10812. sysactcount integer,
  10813. meansactcount integer,
  10814. id_checkpoint integer,
  10815. id_meta_dictionary integer,
  10816. nrecord_tasktype integer,
  10817. authorsid varchar(2000),
  10818. mainempsid varchar(2000),
  10819. numerator varchar(100),
  10820. issecret smallint,
  10821. newactcount integer,
  10822. is_commited smallint,
  10823. ctrlid integer,
  10824. id_last_viewed_act integer,
  10825. lastchange timestamp,
  10826. isuseparentdocs smallint,
  10827. is_show_task smallint)
  10828. as
  10829. declare variable gt_lastchange timestamp;
  10830. declare variable ta_lastchange timestamp;
  10831. declare variable i integer;
  10832. declare variable cnt integer;
  10833. declare variable execdocumentid varchar(1000);
  10834. declare variable l_ishidden integer;
  10835. declare variable sid integer;
  10836. begin
  10837. for select TASKID, TASKNAME, ISGROUP,
  10838. AMIAUTHOR, PRJID, IsReported,
  10839. /* AuthorId, EmpId, */IsRejected, IsWithReport,
  10840. taskdesc, startdate, enddate, task_type,
  10841. documentid, priority, deppath, state, IsOnlyForView, UserId, Send_Actions,
  10842. ExecDocumentId, ID_REALAUTHOR, ID_TASKINITIATOR, PARENTID, is_have_isolated, id_checkpoint
  10843. , id_meta_dictionary, nrecord_tasktype,numerator
  10844. from Informer2_Getmytasks1(:ID_EMPLOYER, :ATASKID)
  10845. into :TASKID, :TASKNAME, :ISGROUP,
  10846. :AMIAUTHOR, :PRJID, :IsReported,
  10847. /* :AuthorId, :EmpId,*/ :IsRejected, :IsWithReport,
  10848. :taskdesc, :startdate, :enddate, :task_type,
  10849. :documentid, :priority, :deppath, :state, :IsOnlyForView, :UserId, :Send_Actions,
  10850. :ExecDocumentId, :ID_REALAUTHOR, :ID_TASKINITIATOR,:PARENTID, :is_have_isolated, :id_checkpoint
  10851. ,:id_meta_dictionary, :nrecord_tasktype,:numerator
  10852. do
  10853. if (TaskId=ATaskId or TaskId>MinTaskId)
  10854. then begin
  10855. if (DocumentId is null and ExecDocumentId is null) then OrderType=0;
  10856. else
  10857. if (DocumentId is not null) then OrderType=1;
  10858. else
  10859. if (ExecDocumentId is not null)
  10860. then begin
  10861. OrderType=2;
  10862. DocumentId=ExecDocumentId;
  10863. end
  10864. ISNEWMESSAGES=0;
  10865. EXECUTE PROCEDURE informer2_gettaskids(ID_EMPLOYER, TASKID, IsOnlyForView) returning_values :EMPSID, :CTRLSID, :SIGNSID,
  10866. :AuthorId, :EmpId , :AUTHORSID , :MAINEMPSID, :CTRLID;
  10867. LastActDate=NULL;
  10868. LastActId=-1;
  10869. LastActId=-1;
  10870. ActCount=0;
  10871. LASTACT='';
  10872. LASTACTEMPID=-1;
  10873. idfolder=0;
  10874. newactcount=0;
  10875. MyColor=NULL;
  10876. cnt=NULL;
  10877. select ta.marker_color, ta.count_actions_view, ta.is_view_new_actions, ta.Id_last_viewed_action
  10878. from task_attributes ta
  10879. where ta.id_employer=:id_employer and
  10880. ta.id_task=:taskid
  10881. into :mycolor, :cnt, :ISNEWMESSAGES, :Id_last_viewed_act;
  10882. select o_result
  10883. from CheckTaskViewed(:ID_EMPLOYER, :taskid)
  10884. into :isviewed;
  10885. select t.la_id, t.action_count, t.sysaction_count, t.meansaction_count, t.issecret, t.isuseparentdocs
  10886. from Task t
  10887. where id= :TaskId
  10888. into :LastActId, :ActCount, :sysactcount, :meansactcount, :issecret, :isuseparentdocs;
  10889. if (isuseparentdocs=1) then
  10890. begin
  10891. SELECT O_DocumentID, O_DocumentName FROM getparentdocs(:TaskID)
  10892. into :Documentid, :Documentname;
  10893. end
  10894. if (ActCount is null) then ActCount=0;
  10895. ACount=ActCount;
  10896. if ((ISNEWMESSAGES=1)or(ISNEWMESSAGES is null)or :ActCount=0)
  10897. then ISNEWMESSAGES=0;
  10898. else ISNEWMESSAGES=1;
  10899. if (LastActId is null) then LastActId=0;
  10900. if (LastActId>0) then
  10901. begin
  10902. select adate, Name, ID_Employer
  10903. from Actions
  10904. where id= :LastActId
  10905. into :LastActDate, :LASTACT, :LASTACTEMPID;
  10906. end
  10907. execute procedure Informer2_TaskAtt(:taskid, -1, -1)
  10908. returning_values :att;
  10909.  
  10910. if (MyColor is null) then MyColor=0;
  10911. select O_RECIVE_SMS, O_RECIVE_MAIL
  10912. from GET_TASK_MAIL_SMS(:TaskId, :id_employer)
  10913. into :receive_sms, :receive_mail;
  10914.  
  10915. if (cnt is null) then lastacount=0;
  10916. else lastacount=cnt;
  10917. newactcount=acount-lastacount;
  10918. isresolution=null;
  10919. btn=null;
  10920. select first 1 rt.isresolution, rt.button_caption from routetrees rt
  10921. where rt.id_task = :taskid and
  10922. rt.isvirtual = 0 and
  10923. rt.isdeleted = 0 and
  10924. (exists(select id from routenode rn
  10925. where rn.id_routetree = rt.id and
  10926. rn.id_employer = :id_employer and
  10927. rn.isdeleted = 0))
  10928. into :isresolution, :btn;
  10929. if (isresolution is null) then isresolution=0;
  10930. DocumentName='';
  10931. DocumentTypeId=NULL;
  10932. DocVersion=NULL;
  10933. select Field1, ID_DocType, Doc_Version
  10934. from Documents
  10935. where id= :DocumentId
  10936. into :DocumentName, :DocumentTypeId, :DocVersion;
  10937. i=1;
  10938. if (OrderType=1) then
  10939. begin
  10940. select O_result from documentcommited (:id_employer, :taskid)
  10941. into :is_commited;
  10942. if (is_commited=1) then
  10943. if (not (exists(select first 1 id_task from grouptask where id_task=:TaskId and
  10944. id_employer=:ID_employer and is_controler=1)))
  10945. then i=0;
  10946. end
  10947. else is_commited=0;
  10948. if (IsOnlyForView is null) then IsOnlyForView=0;
  10949. if (IsOnlyForView=1) then
  10950. begin
  10951. /* SignsId=''; */
  10952. if (exists (select first 1 id
  10953. from Actions
  10954. where id_task=:TaskId and
  10955. examinated=1 and
  10956. (id_employer= :id_employer or id_employer in (select O_EMPLOYERID from
  10957.  
  10958. GETEMPLOYERALIASES(:id_employer)))
  10959. ))
  10960. then i=0;
  10961. else begin
  10962. i=1;
  10963. end
  10964. end
  10965. /*if user needs information by the only one task,
  10966. then return this task in any case*/
  10967. if ((i=0) and (ATASKID<>-1)) then i=1;
  10968. if (i=1) then
  10969. begin
  10970. showdate=NULL;
  10971. select gt.show_task_date
  10972. from grouptask gt
  10973. where gt.id_task=:taskid and gt.id_employer=:id_employer
  10974. into :showdate;
  10975.  
  10976. ISSECRETARY=0;
  10977. if (exists(select * from grouptask gr where gr.id_task=:TaskId
  10978. AND GR.id_employer=:id_employer and gr.is_shadow=1)) then
  10979. ISSECRETARY=1;
  10980. --повесит пережитком
  10981. ISCONTROL=0;
  10982.  
  10983. SELECT
  10984. t.lastchange,
  10985. ta.lastchange,
  10986. gt.lastchange
  10987. FROM
  10988. task t
  10989. left join task_attributes ta on (ta.id_task = t.id and ta.id_employer = :id_employer)
  10990. left join grouptask gt on (gt.id_task = t.id and gt.id_employer = :id_employer)
  10991. WHERE
  10992. t.id = :taskid
  10993. INTO
  10994. :lastchange,
  10995. :ta_lastchange,
  10996. :gt_lastchange;
  10997.  
  10998. if (:ta_lastchange > :lastchange) then
  10999. begin
  11000. lastchange = :ta_lastchange;
  11001. end
  11002.  
  11003. if (:gt_lastchange > :lastchange) then
  11004. begin
  11005. lastchange = :gt_lastchange;
  11006. end
  11007.  
  11008. is_show_task = 0;
  11009.  
  11010. if (is_show_task = 0) then
  11011. begin
  11012.  
  11013. if (exists ( select
  11014. first (1) gt.id_task
  11015. from
  11016. grouptask gt
  11017. where
  11018. gt.id_task = :taskid and
  11019. (
  11020. gt.id_original = :id_employer OR
  11021. gt.id_original = (select parentid from employer where id = :id_employer)
  11022. )
  11023. and
  11024. (
  11025. gt.is_author = 1 OR
  11026. gt.is_respperson = 1 OR
  11027. gt.is_worker = 1 OR
  11028. gt.is_controler = 1 OR
  11029. gt.is_shadow = 1
  11030. )
  11031. )
  11032. )
  11033. then
  11034. is_show_task = 1;
  11035.  
  11036.  
  11037. if (is_show_task = 1) then
  11038. if (exists( select
  11039. first (1) gt.id_task
  11040. from
  11041. grouptask gt
  11042. join task t on
  11043. t.id = gt.id_task
  11044. where
  11045. gt.id_task = :taskid and
  11046. t.is_isolated = 1 and
  11047. (
  11048. gt.id_original = :id_employer OR
  11049. gt.id_original = (select parentid from employer where id = :id_employer)
  11050. )
  11051. and
  11052. (
  11053. gt.is_author = 1 OR
  11054. gt.is_respperson = 1 OR
  11055. gt.is_worker = 1 OR
  11056. gt.is_controler = 1 OR
  11057. gt.is_shadow = 1
  11058. )
  11059. and exists
  11060. (
  11061. select
  11062. first (1) id_task
  11063. from
  11064. grouptask
  11065. where
  11066. id_task = (select parentid from task where id = :taskid) and
  11067. (
  11068. id_original = :id_employer OR
  11069. id_original = (select parentid from employer where id = :id_employer)
  11070. )
  11071. and
  11072. (
  11073. is_author = 1 OR
  11074. is_respperson = 1 OR
  11075. is_worker = 1 OR
  11076. is_controler = 1 OR
  11077. is_shadow = 1
  11078. )
  11079. )
  11080. )
  11081. )
  11082. then
  11083. is_show_task = 0;
  11084.  
  11085. end
  11086.  
  11087. suspend;
  11088. end
  11089. end
  11090. end^
  11091. SET TERM ; ^
  11092. commit;
  11093.  
  11094. /*INFORMER2_GETMYTASKS1*/
  11095. SET TERM ^ ;
  11096. CREATE OR ALTER PROCEDURE INFORMER2_GETMYTASKS1 (
  11097. id_employer integer,
  11098. ataskid integer)
  11099. returns (
  11100. taskid integer,
  11101. taskname varchar(2000),
  11102. isgroup smallint,
  11103. amiauthor smallint,
  11104. prjid integer,
  11105. isreported smallint,
  11106. authorid integer,
  11107. empid integer,
  11108. isrejected smallint,
  11109. iswithreport smallint,
  11110. taskdesc varchar(10000),
  11111. startdate timestamp,
  11112. enddate timestamp,
  11113. task_type smallint,
  11114. documentid integer,
  11115. priority smallint,
  11116. deppath varchar(2000),
  11117. state smallint,
  11118. isonlyforview smallint,
  11119. userid integer,
  11120. send_actions smallint,
  11121. execdocumentid integer,
  11122. id_realauthor integer,
  11123. id_taskinitiator integer,
  11124. parentid integer,
  11125. is_have_isolated integer,
  11126. id_checkpoint integer,
  11127. id_meta_dictionary integer,
  11128. nrecord_tasktype integer,
  11129. numerator varchar(1000))
  11130. as
  11131. declare variable i integer;
  11132. declare variable is_author integer;
  11133. declare variable is_respperson integer;
  11134. declare variable is_controller integer;
  11135. declare variable is_worker integer;
  11136. declare variable is_shadow integer;
  11137. declare variable tid integer;
  11138. declare variable id_dep integer;
  11139. begin
  11140.  
  11141.  
  11142. UserId=ID_EMPLOYER;
  11143. TASK_TYPE = 0;
  11144. if (ATaskId<>-1)
  11145. then
  11146.  
  11147. begin
  11148.  
  11149. select O_RESULT
  11150. from CHECKRIGHTSFORTASK(:ID_EMPLOYER, :ATASKID)
  11151. into :i;
  11152.  
  11153. if (i=0 or (i is null) )
  11154. then begin
  11155. TaskId=-1;
  11156. suspend;
  11157. exit;
  11158. end
  11159.  
  11160. select
  11161.  
  11162. t.id, t.name, t.isgroup, t.id_project, t.isreported,
  11163. (case dt.id_task when dt.id_task then 2 else t.isrejected
  11164.  
  11165. end), t.iswithreport,
  11166. t.description, t.startdate, t.enddate, t.id_document,
  11167. t.Priority,
  11168.  
  11169. t.State, t.IsOnlyForView, t.Send_Actions,
  11170. t.ID_Document_Exec, t.ID_REALAUTHOR, t.ID_TASKINITIATOR,t.PARENTID,
  11171.  
  11172.  
  11173. t.is_have_isolated, t.id_checkpoint, t.id_meta_dictionary, t.nrecord_tasktype,t.numerator
  11174. from task t
  11175.  
  11176.  
  11177. left join documenttaskrestore dt on dt.id_task = t.id
  11178. where t.Id= :ATaskId
  11179. into :TASKID, :TASKNAME, :ISGROUP,
  11180.  
  11181. :PrjId, :IsReported,
  11182. :IsRejected, :iswithreport,
  11183. :taskdesc, :startdate, :enddate, :documentid,
  11184.  
  11185.  
  11186. :Priority, :State, :IsOnlyForView, :Send_Actions,
  11187. :ExecDocumentId, :ID_REALAUTHOR, :ID_TASKINITIATOR,:PARENTID,
  11188.  
  11189.  
  11190. :is_have_isolated, :id_checkpoint, :id_meta_dictionary, :nrecord_tasktype,:numerator;
  11191.  
  11192.  
  11193. /*вычисляем deppath*/
  11194. deppath = null;
  11195.  
  11196. select
  11197. d.deppath
  11198. from
  11199. task t
  11200. join department d on
  11201. d.id = t.id_department
  11202. where
  11203. t.id = :ataskid
  11204. into
  11205. :deppath;
  11206.  
  11207. if (deppath is null) then
  11208. begin
  11209. select first (1)
  11210. d.deppath, d.id
  11211. from
  11212. grouptask g
  11213. join task t on g.id_task = t.id
  11214. join employer e on g.id_employer = e.id
  11215. join department d on e.id_department = d.id
  11216. where
  11217. g.id_task = :ATaskID and
  11218. g.is_respperson = 1
  11219. into :DepPath, :id_dep;
  11220.  
  11221. update task set id_department =:id_dep where id = :ataskid;
  11222. end
  11223.  
  11224. suspend;
  11225. exit;
  11226. end
  11227.  
  11228. for select gt.id_task
  11229. from grouptask gt, task t
  11230. where gt.id_original=:id_employer
  11231. and gt.task_state=0
  11232. and t.id=gt.id_task
  11233. and
  11234. (
  11235. (gt.is_show_task=1)
  11236. or ((t.id_document>0)and(t.is_isolated=0)and(gt.is_controler=1))
  11237. )
  11238. into :TID
  11239.  
  11240. do begin
  11241. select
  11242.  
  11243. t.id, t.name, t.isgroup, t.id_project, t.isreported,
  11244. t.isrejected, t.iswithreport,
  11245. t.description,
  11246.  
  11247. t.startdate, t.enddate, t.id_document,
  11248. t.Priority, t.State, t.IsOnlyForView, t.Send_Actions,
  11249.  
  11250.  
  11251. t.ID_Document_Exec, t.ID_REALAUTHOR, t.ID_TASKINITIATOR,t.PARENTID,
  11252. t.is_have_isolated, t.id_checkpoint,
  11253.  
  11254. t.id_meta_dictionary, t.nrecord_tasktype,t.numerator
  11255. from task t
  11256. where t.id=:TID
  11257. into :TASKID, :TASKNAME,
  11258.  
  11259. :ISGROUP, :PrjId, :IsReported,
  11260. :IsRejected, :iswithreport,
  11261. :taskdesc, :startdate, :enddate, :documentid,
  11262.  
  11263.  
  11264. :Priority, :State, :IsOnlyForView, :send_actions ,
  11265. :ExecDocumentId, :ID_REALAUTHOR,
  11266.  
  11267. :ID_TASKINITIATOR,:PARENTID,
  11268. :is_have_isolated, :id_checkpoint, :id_meta_dictionary, :nrecord_tasktype,:numerator;
  11269.  
  11270.  
  11271.  
  11272. AMIAUTHOR=0;
  11273. for
  11274. select g.is_author
  11275. from grouptask g
  11276. where g.id_task=:TID and
  11277. g.id_original=:id_Employer
  11278. into :is_author
  11279. do begin
  11280. is_author=is_author;
  11281. if (is_author=1)
  11282. then AMIAUTHOR=1;
  11283. end
  11284. suspend;
  11285. end
  11286. end ^
  11287. SET TERM ; ^
  11288. commit;
  11289.  
  11290. /*INFORMER2_GETMYTASKS_WOR*/
  11291. SET TERM ^ ;
  11292. CREATE OR ALTER PROCEDURE INFORMER2_GETMYTASKS_WOR (
  11293. id_employer integer,
  11294. ataskid integer,
  11295. mintaskid integer)
  11296. returns (
  11297. taskid integer,
  11298. taskname varchar(2000),
  11299. isviewed smallint,
  11300. isgroup smallint,
  11301. isnewmessages smallint,
  11302. amiauthor smallint,
  11303. prjid integer,
  11304. isreported smallint,
  11305. authorid integer,
  11306. empid integer,
  11307. isrejected smallint,
  11308. iswithreport smallint,
  11309. lastactid integer,
  11310. taskdesc varchar(10000),
  11311. startdate timestamp,
  11312. enddate timestamp,
  11313. actcount integer,
  11314. att varchar(6000),
  11315. task_type smallint,
  11316. ordertype smallint,
  11317. documentid integer,
  11318. priority smallint,
  11319. lastactdate timestamp,
  11320. empsid varchar(6000),
  11321. deppath varchar(2000),
  11322. state smallint,
  11323. lastact varchar(10000),
  11324. lastactempid integer,
  11325. isonlyforview smallint,
  11326. userid integer,
  11327. mycolor smallint,
  11328. send_actions smallint,
  11329. receive_mail smallint,
  11330. receive_sms smallint,
  11331. acount integer,
  11332. lastacount integer,
  11333. documentname varchar(1000),
  11334. documenttypeid integer,
  11335. isresolution smallint,
  11336. id_realauthor integer,
  11337. id_taskinitiator integer,
  11338. docversion integer,
  11339. btn varchar(200),
  11340. parentid integer,
  11341. showdate timestamp,
  11342. idfolder integer,
  11343. issecretary smallint,
  11344. iscontrol smallint,
  11345. ctrlsid varchar(2000),
  11346. signsid varchar(2000),
  11347. id_meta_dictionary integer,
  11348. nrecord_tasktype integer,
  11349. authorsid varchar(2000),
  11350. mainempsid varchar(2000),
  11351. numerator varchar(100),
  11352. issecret smallint)
  11353. as
  11354. declare variable i integer;
  11355. declare variable cnt integer;
  11356. declare variable execdocumentid varchar(1000);
  11357. declare variable l_ishidden integer;
  11358. declare variable sid integer;
  11359. begin
  11360. for select TASKID, TASKNAME, ISGROUP,
  11361. AMIAUTHOR, PRJID, IsReported,
  11362. /* AuthorId, EmpId,*/ IsRejected, IsWithReport,
  11363. taskdesc, startdate, enddate, task_type,
  11364. documentid, priority, deppath, state, IsOnlyForView, UserId, Send_Actions,
  11365. ExecDocumentId, ID_REALAUTHOR, ID_TASKINITIATOR, PARENTID, numerator
  11366. from Informer2_Getmytasks1(:ID_EMPLOYER, :ATASKID)
  11367. into :TASKID, :TASKNAME, :ISGROUP,
  11368. :AMIAUTHOR, :PRJID, :IsReported,
  11369. /* :AuthorId, :EmpId,*/ :IsRejected, :IsWithReport,
  11370. :taskdesc, :startdate, :enddate, :task_type,
  11371. :documentid, :priority, :deppath, :state, :IsOnlyForView, :UserId, :Send_Actions,
  11372. :ExecDocumentId, :ID_REALAUTHOR, :ID_TASKINITIATOR,:PARENTID, :numerator
  11373. do
  11374. if (TaskId=ATaskId or TaskId>MinTaskId ) then
  11375. begin
  11376. if (DocumentId is null and ExecDocumentId is null) then OrderType=0;
  11377. else
  11378. if (DocumentId is not null) then OrderType=1;
  11379. else
  11380. if (ExecDocumentId is not null) then
  11381. begin
  11382. OrderType=2;
  11383. DocumentId=ExecDocumentId;
  11384. end
  11385. ISNEWMESSAGES=0;
  11386. select ig.Empsid, ig.Ctrlsid, ig.Signsid, ig.Authorid, ig.Empid, ig.Authorsid, ig.Mainempsid
  11387. from informer2_gettaskids(:ID_EMPLOYER,:TASKID,:IsOnlyForView) ig
  11388. into :EMPSID, :CTRLSID, :SIGNSID, :AuthorId, :EmpId , :AUTHORSID , :MAINEMPSID;
  11389.  
  11390. LastActDate=NULL;
  11391. LastActId=-1;
  11392. ActCount=0;
  11393. LASTACT='';
  11394. LASTACTEMPID=-1;
  11395. select t.la_id, t.action_count
  11396. from Task t
  11397. where id= :TaskId
  11398. into :LastActId, :ActCount;
  11399. if (LastActId is null) then LastActId=0;
  11400. if (LastActId>0) then
  11401. begin
  11402. select adate, Name, ID_Employer
  11403. from Actions
  11404. where id= :LastActId
  11405. into :LastActDate, :LASTACT, :LASTACTEMPID;
  11406. end
  11407. if (ActCount is null) then ActCount=0;
  11408. ACount=ActCount;
  11409. execute procedure Informer2_TaskAtt(:taskid, :documentid, -1) returning_values :att;
  11410. LastActDate=NULL;
  11411. LastActId=-1;
  11412. ActCount=0;
  11413. LASTACT='';
  11414. LASTACTEMPID=-1;
  11415. idfolder=0;
  11416. MyColor=NULL;
  11417. select ta.marker_color, ta.count_actions_view, ta.is_view_new_actions
  11418. from task_attributes ta
  11419. where ta.id_employer=:id_employer and
  11420. ta.id_task=:taskid
  11421. into :mycolor, :cnt, :ISNEWMESSAGES;
  11422. select o_result
  11423. from CheckTaskViewed(:ID_EMPLOYER, :taskid)
  11424. into :isviewed;
  11425. if (MyColor is null) then MyColor=0;
  11426. select O_RECIVE_SMS, O_RECIVE_MAIL
  11427. from GET_TASK_MAIL_SMS(:TaskId, :id_employer)
  11428. into :receive_sms, :receive_mail;
  11429. if (cnt is null) then lastacount=0;
  11430. else lastacount=cnt;
  11431. isresolution=null;
  11432. btn=null;
  11433. select first 1 rt.isresolution, rt.button_caption from routetrees rt
  11434. where rt.id_task = :taskid and
  11435. rt.isvirtual = 0 and
  11436. rt.isdeleted = 0 and
  11437. (exists(select id from routenode rn
  11438. where rn.id_routetree = rt.id and
  11439. rn.id_employer = :id_employer and
  11440. rn.isdeleted = 0))
  11441. into :isresolution, :btn;
  11442. if (isresolution is null) then isresolution=0;
  11443. DocumentName='';
  11444. DocumentTypeId=NULL;
  11445. DocVersion=NULL;
  11446. select Field1, ID_DocType, Doc_Version
  11447. from Documents
  11448. where id= :DocumentId
  11449. into :DocumentName, :DocumentTypeId, :DocVersion;
  11450. if (OrderType=1) then
  11451. begin
  11452. select O_result from documentcommited (:id_employer, :taskid)
  11453. into :i;
  11454. if (i=1) then i=0;
  11455. else i=1;
  11456. end
  11457. else i=1;
  11458. if (IsOnlyForView is null) then IsOnlyForView=0;
  11459. if (IsOnlyForView=1) then
  11460. begin
  11461. SignsId='';
  11462. if (exists (select first 1 id
  11463. from Actions
  11464. where id_task=:TaskId and
  11465. examinated=1 and
  11466. (id_employer= :id_employer or id_employer in (select O_EMPLOYERID from GETEMPLOYERALIASES(:id_employer)))
  11467. ))
  11468. then i=0;
  11469. else begin -- задача
  11470. i=1;
  11471.  
  11472. end
  11473. end
  11474. if (i=1) then
  11475. begin
  11476. showdate=NULL;
  11477. select ht.showdate
  11478. from hiddentasks ht
  11479. where ht.id_task=:taskid and ht.id_employer=:id_employer
  11480. into :showdate;
  11481. ISSECRETARY=0;
  11482. if (ISGROUP=1) then
  11483. BEGIN
  11484. if (exists(select * from grouptask gr where gr.id_task=:TaskId
  11485. AND GR.id_employer=:id_employer and gr.is_shadow=1)) then
  11486. ISSECRETARY=1;
  11487. END
  11488. ISCONTROL=0;
  11489. /* suspend; */
  11490. end
  11491. suspend;
  11492. end
  11493. end^
  11494. SET TERM ; ^
  11495. commit;
  11496.  
  11497. /*INFORMER2_GETMYWORKGR*/
  11498. SET TERM ^ ;
  11499. CREATE OR ALTER PROCEDURE INFORMER2_GETMYWORKGR (
  11500. empid integer,
  11501. taskid_ integer)
  11502. returns (
  11503. taskid integer,
  11504. parenttaskid integer,
  11505. empsid varchar(4000),
  11506. cascadepostsystemactions integer,
  11507. taskstate smallint,
  11508. wgids varchar(4000),
  11509. iwg_name varchar(2000))
  11510. as
  11511. declare variable tid integer;
  11512. declare variable mempid integer;
  11513. declare variable isreported integer;
  11514. begin
  11515. /* Procedure Text */
  11516. if (taskid_<>-1)
  11517. then begin
  11518. for
  11519. select tt.id, tt.IS_POST_SYSACTIONS_TO_PARENT, tt.parentid, tt.state, tt.isreported, tt.irg_name
  11520. from task tt
  11521. where (tt.parentid=:taskid_) and (tt.is_isolated=1)
  11522. into :taskid, :cascadepostsystemactions, :PARENTTASKID, :taskstate, :iSREPORTED, :IWG_NAME
  11523. do begin
  11524. select EMPSID, MAINEMPSID from informer2_gettaskids(:EMPID, :taskid, 0)
  11525. into :WGIDS, :EMPSID;
  11526. /* EMPSID=:MEMPID||';'||:EMPSID; */
  11527. if ((:taskstate<>1)and(:iSREPORTED=1)) then taskstate=2;
  11528. suspend;
  11529. end
  11530. end
  11531. else
  11532. for select gt.id_task
  11533. from grouptask gt, task t
  11534. where gt.id_original=:empid and gt.task_state=0 and gt.is_show_task=1
  11535. and t.id=gt.id_task and t.is_have_isolated=1
  11536. into :PARENTTASKID
  11537. do begin
  11538. for
  11539. select tt.id, tt.IS_POST_SYSACTIONS_TO_PARENT, tt.state, tt.isreported,
  11540. tt.irg_name
  11541. from task tt
  11542. where (tt.parentid=:PARENTTASKID) and (tt.is_isolated=1)
  11543. into :taskid, :cascadepostsystemactions, :taskstate, :ISREported, :IWG_NAME
  11544. do begin
  11545. select EMPSID, MAINEMPSID from informer2_gettaskids(:EMPID, :taskid, 0)
  11546. into :WGIDS, :EMPSID;
  11547. if ((:taskstate<>1)and(:iSREPORTED=1)) then taskstate=2;
  11548. suspend;
  11549. end
  11550. end
  11551. end^
  11552. SET TERM ; ^
  11553. commit;
  11554.  
  11555. /*INFORMER2_NEWACTIONSFOREMPLOYER*/
  11556. SET TERM ^ ;
  11557. CREATE OR ALTER PROCEDURE INFORMER2_NEWACTIONSFOREMPLOYER (
  11558. minactid integer,
  11559. employerid integer)
  11560. returns (
  11561. actid integer,
  11562. act varchar(10000),
  11563. adate timestamp,
  11564. class smallint,
  11565. empid integer,
  11566. taskid integer,
  11567. att varchar(8000),
  11568. signature blob sub_type 0 segment size 80,
  11569. subtaskid integer,
  11570. id_document integer,
  11571. docname varchar(1000),
  11572. doctype varchar(200),
  11573. doc_create_date timestamp,
  11574. docauthor varchar(2000))
  11575. as
  11576. declare variable filename varchar(260);
  11577. declare variable description varchar(200);
  11578. declare variable displayfilename varchar(1000);
  11579. declare variable i integer;
  11580. BEGIN
  11581. /* для снятия нагрузки*/
  11582. if (gen_id(GEN_ENABLED_INF_PROC,0)<>1) then exit;
  11583. if (MinActId=0) then exit;
  11584. for
  11585. select distinct gt.id_task
  11586. from grouptask gt
  11587. where gt.id_original=:EMPLOYERID and gt.task_state=0 and gt.is_show_task=1
  11588. into :TaskId
  11589. do
  11590. begin
  11591. FOR
  11592. select a.NAME,a.id_document, d.field1 as docname, dt.name as doctype,d.createdate as Doc_Create_Date,e.name as DocAuthor,
  11593. a.ADATE, a.id, a.class, a.id_employer, a.signature, a.id_subtask
  11594. from ACTIONS a
  11595. left join documents d on (d.id = a.id_document)
  11596. left join doctypes dt on (dt.id=d.id_doctype)
  11597. left join employer e on (e.id=d.id_author)
  11598. where a.ID>:MinActId and a.ID_Task= :TaskId
  11599. order by a.Id_Task, a.Adate
  11600. INTO :Act,:id_document,:docname,:doctype, :doc_create_date, :docauthor, :ADate, :ActId, :Class, :EmpId,:Signature, :subtaskid
  11601. DO
  11602. BEGIN
  11603. Att='';
  11604. if (subtaskid is null) then subtaskid=0;
  11605. for select FILENAME, DESCRIPTION, displayfilename
  11606. from ATTACHMENT
  11607. where ISDELETED=0 and ID_ACTION=:ActId
  11608. into :FileName, :Description,:displayfilename
  11609. do
  11610. begin
  11611. if (Description is null) then Description='';
  11612. if (DisplayFileName is null) then DisplayFileName=FileName;
  11613. Att=Att||'/Upload/'||:TaskId||'/'||FileName||'<,>'||Description||'<,>'||DisplayFileName||'<;>';
  11614. end
  11615. SUSPEND;
  11616. END
  11617. end
  11618. END^
  11619. SET TERM ; ^
  11620. commit;
  11621.  
  11622. /*task_au0*/
  11623. SET TERM ^ ;
  11624. CREATE OR ALTER trigger task_au0 for task
  11625. active before update position 0
  11626. as
  11627. declare variable task_id int;
  11628. declare variable task_count int;
  11629. declare variable l_idroutetree integer;
  11630. declare variable l_idemployer integer;
  11631. declare variable l_idnotice integer;
  11632. declare variable l_id_docexec integer;
  11633. declare variable l_task_valuation_id integer;
  11634. begin
  11635. --закрывается, без доклада
  11636. if (new.iswithreport = 0 and old.state = 0 and new.state = 1) then new.tsreport = 'now';
  11637. --доклад отправлен, задача не закрыта
  11638. if (new.iswithreport = 1) then
  11639. begin
  11640. --anee aieeaa ioi?aaeai, ii caaa?a au? ia cae?uoa
  11641. if (old.isreported=0 and new.isreported=1 and new.state = 0) then
  11642. new.respp_report = 'now';
  11643. --задача закрыта
  11644. if (old.state = 0 and new.state = 1) then
  11645. new.tsreport = 'now';
  11646. --возвращена на доработку
  11647. if (old.isreported=1 and new.isreported=0 and new.state = 0) then
  11648. new.respp_report = null;
  11649. end
  11650. if (new.isdeleted=1 and old.isdeleted =0) then /*удаляем задачу - удаляем атачи */
  11651. begin
  11652. update attachment set isdeleted = 1
  11653. where id_task=new.id;
  11654. /* удаляем проект - кроме проекта по умолчанию */
  11655. if (not exists(select id
  11656. from task where
  11657. id!=new.id and id_project=new.id_project and isdeleted=0)) then
  11658. update project
  11659. set isdeleted = 1
  11660. where id=new.id_project and istrash=0;
  11661. end
  11662. if (new.isdeleted=1 and old.isdeleted =0) then /*удаляем задачу - удаляем атачи */
  11663. begin
  11664. update attachment set isdeleted = 1
  11665. where id_task=new.id;
  11666. end
  11667. /* меняем task_state в grouptask */
  11668. update grouptask set task_state=new.state
  11669. where id_task=new.id and (task_state != new.state or task_state is null);
  11670. if (new.state =1 and old.state = 0) then /*закрытие задачи - снимаем с контроля*/
  11671. begin
  11672. delete from hiddentasks where id_task=new.id;
  11673. select count (id) from task
  11674. where id_project =old.id_project
  11675. and state= 0
  11676. into :task_count;
  11677. if (task_count =1) then /*последняя задача - закрываем проект*/
  11678. begin
  11679. select id from task where id_project = new.id_project
  11680. and state =0
  11681. into :task_id;
  11682. if (task_id = old.id) then
  11683. update project
  11684. set state=1
  11685. where id=old.id_project;
  11686. end
  11687. /*напоминания*/
  11688. for select n.id from notice n where n.id_task = new.id
  11689. into :l_idnotice do
  11690. begin
  11691. execute procedure delete_notice(:l_idnotice);
  11692. end
  11693.  
  11694. end
  11695. if (new.state = 0 and old.state = 1) then /*восстановление задачи + проект*/
  11696. begin
  11697. update project set state=0
  11698. where id=new.id_project and state!=0;
  11699. new.id_valuation=null;/*сбрасываем оценку восстановленной*/
  11700. update grouptask gt set gt.is_viewed_task=0 where gt.id_task=new.id;
  11701. update actions a set a.examinated=0 where a.examinated=1 and a.id_task=new.id;
  11702. end
  11703. if (new.id_project <> old.id_project) then --ia?aiin ec i?iaeoa a i?iaeo - ia?aiinei ana oianeaaiaaiiua caaa?e
  11704. begin
  11705. /*закрываем проект*/
  11706. select count (id) from task
  11707. where id_project =old.id_project
  11708. and state= 0
  11709. into :task_count;
  11710. if (task_count =1) then
  11711. begin
  11712. select id from task where id_project = old.id_project
  11713. and state =0
  11714. into :task_id;
  11715. if (task_id = old.id) then
  11716. update project set state=1
  11717. where id=old.id_project;
  11718. end
  11719. end
  11720. end^
  11721. SET TERM ; ^
  11722. commit;
  11723.  
  11724. /*и удалим все что лишнее*/
  11725. SET TERM ^ ;
  11726. CREATE OR ALTER PROCEDURE TMP_DROP_FAVORITS
  11727. AS
  11728. declare variable is_exist smallint;
  11729. BEGIN
  11730. /*сначала процедуры. эти две темповые процедуры непонятно откуда взялись*/
  11731. SELECT result FROM IS_PROCEDURE_EXISTS('TMP_CONVERT_FAVTASKS')
  11732. INTO :is_exist;
  11733.  
  11734. IF (is_exist = 1) THEN
  11735. begin
  11736. EXECUTE STATEMENT
  11737. 'DROP PROCEDURE TMP_CONVERT_FAVTASKS;';
  11738. end
  11739.  
  11740. SELECT result FROM IS_PROCEDURE_EXISTS('TMP_DEL_CLOSED_FAVORITES')
  11741. INTO :is_exist;
  11742.  
  11743. IF (is_exist = 1) THEN
  11744. begin
  11745. EXECUTE STATEMENT
  11746. 'DROP PROCEDURE TMP_DEL_CLOSED_FAVORITES;';
  11747. end
  11748.  
  11749. /*это специфичная для этой таблицы процедуры, легко удаляем*/
  11750.  
  11751. SELECT result FROM IS_PROCEDURE_EXISTS('GETFAVORITETASK')
  11752. INTO :is_exist;
  11753.  
  11754. IF (is_exist = 1) THEN
  11755. begin
  11756. EXECUTE STATEMENT
  11757. 'DROP PROCEDURE GETFAVORITETASK;';
  11758. end
  11759.  
  11760. SELECT result FROM IS_PROCEDURE_EXISTS('SETCONTROL')
  11761. INTO :is_exist;
  11762.  
  11763. IF (is_exist = 1) THEN
  11764. begin
  11765. EXECUTE STATEMENT
  11766. 'DROP PROCEDURE SETCONTROL;';
  11767. end
  11768.  
  11769. /*поля*/
  11770.  
  11771. SELECT result FROM IS_FIELD_EXISTS('FAVORITETASKS', 'ID_TASK')
  11772. INTO :is_exist;
  11773.  
  11774. IF (is_exist = 1) THEN
  11775. begin
  11776. EXECUTE STATEMENT
  11777. 'ALTER TABLE FAVORITETASKS DROP CONSTRAINT FK_FAVORITETASKS2;';
  11778. EXECUTE STATEMENT
  11779. 'ALTER TABLE FAVORITETASKS DROP ID_TASK;';
  11780. end
  11781.  
  11782. SELECT result FROM IS_FIELD_EXISTS('FAVORITETASKS', 'ID_EMPLOYER')
  11783. INTO :is_exist;
  11784.  
  11785. IF (is_exist = 1) THEN
  11786. begin
  11787. EXECUTE STATEMENT
  11788. 'ALTER TABLE FAVORITETASKS DROP CONSTRAINT FK_FAVORITETASKS1;';
  11789. EXECUTE STATEMENT
  11790. 'ALTER TABLE FAVORITETASKS DROP ID_EMPLOYER;';
  11791. end
  11792.  
  11793. /*сама таблица*/
  11794.  
  11795. SELECT result FROM IS_TABLE_EXISTS('FAVORITETASKS')
  11796. INTO :is_exist;
  11797.  
  11798. IF (is_exist = 1) THEN
  11799. begin
  11800. EXECUTE STATEMENT
  11801. 'DROP TABLE FAVORITETASKS';
  11802. end
  11803.  
  11804.  
  11805. END ^
  11806. SET TERM ; ^
  11807. commit;
  11808.  
  11809. EXECUTE PROCEDURE TMP_DROP_FAVORITS;
  11810. commit;
  11811. DROP PROCEDURE TMP_DROP_FAVORITS;
  11812. commit;
  11813.  
  11814. /*-------------------------------------------------------------------------------------------------------------------------------*/
  11815. /* ������� ��� �������� ������ ���������� �������� */
  11816. /*-------------------------------------------------------------------------------------------------------------------------------*/
  11817. CREATE TABLE INDEXING_ERRORS (
  11818. ID INTEGER NOT NULL,
  11819. OBJECT_TYPE INTEGER NOT NULL,
  11820. OBJECT_ID INTEGER NOT NULL,
  11821. INFO VARCHAR(1024) NOT NULL,
  11822. EXTENDED_INFO VARCHAR(4096),
  11823.  
  11824. PRIMARY KEY (ID),
  11825. UNIQUE (OBJECT_TYPE, OBJECT_ID)
  11826. );
  11827.  
  11828. CREATE GENERATOR GEN_INDEXING_ERRORS;
  11829. SET TERM ^ ;
  11830. CREATE TRIGGER INDEXING_ERRORS_BI FOR INDEXING_ERRORS
  11831. ACTIVE BEFORE INSERT POSITION 0
  11832. AS
  11833. BEGIN
  11834. if (NEW.ID is NULL) then NEW.ID = GEN_ID(GEN_INDEXING_ERRORS, 1);
  11835. END^
  11836. SET TERM ; ^
  11837. commit;
  11838. commit;
  11839. commit work;
  11840.  
  11841.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement