Browse Source

Version 1.0

master
M@d D3n 4 years ago
parent
commit
864a147a06
  1. 5
      README.md
  2. 310
      admin/edit.tpl
  3. 80
      admin/log.tpl
  4. 155
      admin/main.tpl
  5. 146
      admin/run.tpl
  6. 838
      class/class.php
  7. 20
      css/workdocs.css
  8. 19
      info.php
  9. 360
      js/workdocs.js
  10. 105
      lang/ru.txt
  11. 94
      module.php
  12. 65
      sql.php
  13. 21
      stepone.php

5
README.md

@ -187,5 +187,10 @@ return string<br/>
?>
```
## Changelog:
05.07.2020 - Дата создания
---
Copyright © 2007-2020 [Ave-Cms.Ru](https://ave-cms.ru)

310
admin/edit.tpl

@ -0,0 +1,310 @@
<div class="title">
<h5>{#mod_title#}</h5>
</div>
<div class="widget" style="margin-top: 0px;">
<div class="body">
{#mod_description#}
</div>
</div>
<div class="breadCrumbHolder module">
<div class="breadCrumb module">
<ul>
<li class="firstB"><a href="index.php" title="{#MAIN_PAGE#}">{#MAIN_PAGE#}</a></li>
<li><a href="index.php?do=modules&cp={$sess}">{#MODULES_SUB_TITLE#}</a></li>
<li><a href="index.php?do=modules&action=modedit&mod=workdocs&moduleaction=1&cp={$sess}">{#mod_title#}</a></li>
<li>{#mod_edit_breadcrumb#}</li>
<li>{if $work.title}{$work.title}{else}{$smarty.request.title}{/if}</li>
</ul>
</div>
</div>
<form id="saveForm" action="index.php?do=modules&action=modedit&mod=workdocs&moduleaction=save&cp={$sess}" method="post" class="mainForm">
<input type="hidden" id="work_id" name="work_id" value="{$work_id}">
<input type="hidden" id="rubric_id" name="rubric_id" value="{$rubric_id}">
<div class="widget first">
<div class="head">
<h5>{#mod_edit_settings#}</h5>
<div class="num hideBtn" {if ! $work_id}style="display: none"{/if}>
<a class="basicNum topDir" href="index.php?do=modules&action=modedit&mod=workdocs&moduleaction=run&rubric_id={$rubric_id}&work_id={$work_id}&cp={$sess}">{#mod_edit_btn_run#}</a>
</div>
</div>
<fieldset>
<table cellpadding="0" cellspacing="0" width="100%" class="tableStatic">
<col width="400" />
<col />
<thead>
<tr>
<td colspan="2">{#mod_edit_settings_work#}</td>
</tr>
</thead>
<tr>
<td>{#mod_edit_settings_name#}</td>
<td><input class="mousetrap" name="title" type="text" id="title" value="{$work.title}" placeholder="{#mod_edit_settings_name#}" style="width: 400px" autocomplete="off"></td>
</tr>
<tr>
<td>{#mod_edit_settings_desc#}</td>
<td>
<input class="mousetrap" name="description" type="text" id="title" value="{$work.description}" placeholder="{#mod_edit_settings_desc#}" autocomplete="off">
</td>
</tr>
<tr>
<td>{#mod_edit_settings_rub#}</td>
<td>
<select id="rubric_id_select" name="rubric_id_select" class="mousetrap" disabled>
<option value="">{#mod_edit_settings_rub_sel#}</option>
{foreach from=$rubrics item=rub}
<option value="{$rub.Id}" {if $rubric_id == $rub.Id}selected{/if}>{$rub.rubric_title|escape}</option>
{/foreach}
</select>
</td>
</tr>
<thead>
<tr>
<td colspan="2">{#mod_edit_settings_doc#}</td>
</tr>
</thead>
<tr>
<td>{#mod_edit_settings_doc_1#}</td>
<td>
<div class="pr12">
<input type="radio" name="save_enable" value="1"{if $work.save_enable == 1} checked{/if} /><label style="cursor: pointer;">{#mod_yes#}</label>&nbsp;
<input type="radio" name="save_enable" value="0"{if $work.save_enable == 0} checked{/if} /><label style="cursor: pointer;">{#mod_no#}</label>
</div>
</td>
</tr>
<tr>
<td>{#mod_edit_settings_doc_2#}</td>
<td>
<div class="pr12">
<input type="radio" name="code_enable" value="1"{if $work.code_enable == 1} checked{/if} /><label style="cursor: pointer;">{#mod_yes#}</label>&nbsp;
<input type="radio" name="code_enable" value="0"{if $work.code_enable == 0} checked{/if} /><label style="cursor: pointer;">{#mod_no#}</label>
</div>
</td>
</tr>
<tr>
<td>{#mod_edit_settings_doc_3#}</td>
<td>
<div class="pr12">
<input type="radio" name="revisions_enable" value="1"{if $work.revisions_enable == 1} checked{/if} /><label style="cursor: pointer;">{#mod_yes#}</label>&nbsp;
<input type="radio" name="revisions_enable" value="0"{if $work.revisions_enable == 0} checked{/if} /><label style="cursor: pointer;">{#mod_no#}</label>
</div>
</td>
</tr>
<tr>
<td>{#mod_edit_settings_doc_4#}</td>
<td>
<div class="pr12">
<input type="radio" name="logs_enable" value="1"{if $work.logs_enable == 1} checked{/if} /><label style="cursor: pointer;">{#mod_yes#}</label>&nbsp;
<input type="radio" name="logs_enable" value="0"{if $work.logs_enable == 0} checked{/if} /><label style="cursor: pointer;">{#mod_no#}</label>
</div>
</td>
</tr>
</table>
<div class="rowElem" id="saveBtn">
<div class="saveBtn">
<input class="basicBtn" type="submit" value="Сохранить" />
ИЛИ
<input type="submit" class="blackBtn SaveWork" value="Применить (CTRL + S)" />
</div>
</div>
</fieldset>
</div>
<div class="widget first">
<div class="head">
<h5>{#mod_edit_code_header#}</h5>
<div class="num hideBtn" {if ! $work_id}style="display: none"{/if}>
<a class="basicNum topDir" href="index.php?do=modules&action=modedit&mod=workdocs&moduleaction=step&rubric_id={$rubric_id}&work_id={$work_id}&cp={$sess}" target="_blank">Запустить тест</a>
</div>
</div>
<table cellpadding="0" cellspacing="0" width="100%" class="tableStatic">
<col width="50%">
<col width="50%">
<thead>
<tr>
<td>{#mod_edit_code_header_b#}</td>
<td>{#mod_edit_code_header_a#}</td>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="pr12">
<textarea name="code_before" type="text" id="code_before" value="" style="height:400px;" />{$work.code_before}</textarea>
</div>
</td>
<td>
<div class="pr12">
<textarea name="code_after" type="text" id="code_after" value="" style="height:400px;" />{$work.code_after}</textarea>
</div>
</td>
</tr>
<tr>
<td>
{#mod_edit_code_header_hint#}
</td>
<td>
{#mod_edit_code_header_hint#}
</td>
</tr>
</tbody>
</table>
</div>
<div class="widget first">
<div class="head closed activ">
<h5>{#mod_edit_code_sql_h#}</h5>
</div>
<div style="display: block">
<table cellpadding="0" cellspacing="0" width="100%" class="tableStatic">
<col width="50%">
<col width="50%">
<thead>
<tr>
<td>{#mod_edit_code_sql_hint#}</td>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="pr12">
<textarea name="self_sql" type="text" id="self_sql" value="" style="height:400px;" />{$work.self_sql}</textarea>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="widget first">
<div class="head closed activ">
<h5>{#mod_edit_fields#}</h5>
</div>
<div style="display: block">
<table cellpadding="0" cellspacing="0" width="100%" class="tableStatic">
<col width="30">
<col>
<col width="100">
<col width="200">
<thead>
<tr>
<td>{#mod_edit_fields_table_id#}</td>
<td>{#mod_edit_fields_table_name#}</td>
<td>{#mod_edit_fields_table_alias#}</td>
<td>{#mod_edit_fields_table_type#}</td>
</tr>
</thead>
<tbody>
{foreach from=$fields_list item=field_group}
{if $groups_count > 1}
<tr class="grey">
<td colspan="4">
<h5>{if $field_group.group_title}{$field_group.group_title}{else}{#mod_edit_fields_unknow#}{/if}</h5>
</td>
</tr>
{/if}
{foreach from=$field_group.fields item=field}
<tr>
<td align="center">
<strong class="code">{$field.Id}</strong>
</td>
<td>
<strong>{$field.rubric_field_title}</strong>
</td>
<td align="center">
{if $field.rubric_field_alias}<strong class="code">{$field.rubric_field_alias}</strong>{/if}
</td>
<td>
{section name=field_name loop=$field_array}
{if $field.rubric_field_type == $field_array[field_name].id}{$field_array[field_name].name}{/if}
{/section}
</td>
</tr>
{/foreach}
{/foreach}
</tbody>
</table>
</div>
</div>
<div class="widget first">
<div class="head closed active">
<h5>{#mod_edit_rub_code_h#}</h5>
</div>
<div style="display: block">
<table cellpadding="0" cellspacing="0" width="100%" class="tableStatic">
<col width="50%">
<col width="50%">
<thead>
<tr>
<td>{#mod_edit_rub_code_t1#}</td>
<td>{#mod_edit_rub_code_t2#}</td>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="pr12">
<textarea name="rubric_code_start" type="text" id="rubric_code_start" value="" style="height:300px;" />{$rubric.rubric_code_start}</textarea>
</div>
</td>
<td>
<div class="pr12">
<textarea name="rubric_code_end" type="text" id="rubric_code_end" value="" style="height:300px;" />{$rubric.rubric_code_end}</textarea>
</div>
</td>
</tr>
<tr>
<td>
{#mod_edit_rub_code_hint1#}
</td>
<td>
{#mod_edit_rub_code_hint2#}
</td>
</tr>
</tbody>
</table>
</div>
</div>
</form>
<script type="text/javascript" src="{$ABS_PATH}modules/workdocs/js/workdocs.js"></script>
{literal}
<script type="text/javascript" language="JavaScript">
$(document).ready(function() {
"use strict";
ModuleWorkDocs.init();
ModuleWorkDocs.edit();
});
</script>
{/literal}
{include file="$codemirror_connect"}
{include file="$codemirror_editor" conn_id="sql" textarea_id='self_sql' ctrls='ModuleWorkDocs.saveWork();' height=300}
{include file="$codemirror_editor" conn_id="rfs" textarea_id='code_before' ctrls='ModuleWorkDocs.saveWork();' height=400}
{include file="$codemirror_editor" conn_id="rfe" textarea_id='code_after' ctrls='ModuleWorkDocs.saveWork();' height=400}
{include file="$codemirror_editor" conn_id="rcs" textarea_id='rubric_code_start' ctrls='ModuleWorkDocs.saveWork();' height=300}
{include file="$codemirror_editor" conn_id="rce" textarea_id='rubric_code_end' ctrls='ModuleWorkDocs.saveWork();' height=300}

80
admin/log.tpl

@ -0,0 +1,80 @@
<div class="widget" style="margin-top: 0px;">
<div class="title">
<h5>{#mod_title#}</h5>
<div class="num">
<a class="redNum clearLog" href="index.php?do=modules&action=modedit&mod=workdocs&moduleaction=clear&work_id={$work_id}&cp={$sess}">{#mod_log_btn_clear#}</a>
</div>
</div>
</div>
<div class="widget" style="margin-top: 0px;">
<div class="body">
{#mod_description#}
</div>
</div>
<div class="breadCrumbHolder module">
<div class="breadCrumb module">
<ul>
<li class="firstB"><a href="index.php" title="{#MAIN_PAGE#}">{#MAIN_PAGE#}</a></li>
<li><a href="index.php?do=modules&cp={$sess}">{#MODULES_SUB_TITLE#}</a></li>
<li><a href="index.php?do=modules&action=modedit&mod=workdocs&moduleaction=1&cp={$sess}">{#mod_title#}</a></li>
<li>{#mod_log_breadcrumbs#}</li>
<li>{$work.title}</li>
</ul>
</div>
</div>
<link rel="stylesheet" href="{$ABS_PATH}modules/workdocs/css/workdocs.css">
<div id="stepDocs" class="widget first">
<div class="head">
<h5 class="iFrames">{#mod_log_tbl_docs#}</h5>
</div>
<table cellpadding="0" cellspacing="0" width="100%" class="display" id="logsTable" data-work-id="{$work.id}">
<col width="30">
<col>
<col width="150">
<col width="500">
<thead>
<tr>
<th class="col-id">{#mod_log_tbl_docs_id#}</th>
<th class="col-title">{#mod_log_tbl_docs_name#}</th>
<th class="col-run">{#mod_log_tbl_docs_date#}</th>
<th class="col-logs">{#mod_log_tbl_docs_logs#}</th>
</tr>
</thead>
<tbody>
<tr>
<td class="col-id"></td>
<td class="col-title"></td>
<td class="col-run"></td>
<td class="col-logs"></td>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript" src="{$ABS_PATH}modules/workdocs/js/workdocs.js"></script>
<script type="text/javascript" language="JavaScript">
var logs,
clear_confirm = '{#mod_log_clear_confirm#}',
clear_title = '{#mod_log_clear_title#}',
sLengthMenu = '{#mod_log_sLengthMenu#}',
sZeroRecords = '{#mod_log_sZeroRecords#}',
sInfo = '{#mod_log_sInfo#}',
sInfoEmpty = '{#mod_log_sInfoEmpty#}',
sInfoFiltered = '{#mod_log_sInfoFiltered#}';
{literal}
$(document).ready(function() {
"use strict";
ModuleWorkDocs.init();
ModuleWorkDocs.log();
});
{/literal}
</script>

155
admin/main.tpl

@ -0,0 +1,155 @@
<div class="title">
<h5>{#mod_title#}</h5>
</div>
<div class="widget" style="margin-top: 0px;">
<div class="body">
{#mod_description#}
</div>
</div>
<div class="breadCrumbHolder module">
<div class="breadCrumb module">
<ul>
<li class="firstB"><a href="index.php" title="{#MAIN_PAGE#}">{#MAIN_PAGE#}</a></li>
<li><a href="index.php?do=modules&cp={$sess}">{#MODULES_SUB_TITLE#}</a></li>
<li>{#mod_title#}</li>
</ul>
</div>
</div>
<div class="widget first">
<ul class="tabs">
<li class="activeTab">
<a href="#tab1">{#mod_list_works#}</a>
</li>
<li class="">
<a href="#tab2">{#mod_add_work#}</a>
</li>
<div class="num">
<a class="greenNum clearLogs" href="index.php?do=modules&action=modedit&mod=workdocs&moduleaction=all&cp={$sess}">{#mod_clear_all_logs#}</a>
</div>
</ul>
<div class="tab_container">
<div id="tab1" class="tab_content" style="display: block;">
<table cellpadding="0" cellspacing="0" width="100%" class="tableStatic mainForm">
{if $works}
<col width="30" />
<col />
<col width="150" />
<col width="250" />
<col width="10" />
<col width="10" />
<col width="10" />
<thead>
<tr>
<td>{#mod_main_table_th_id#}</td>
<td>{#mod_main_table_th_name#}</td>
<td>{#mod_main_table_th_run#}</td>
<td>{#mod_main_table_th_rub#}</td>
<td colspan="4">{#mod_main_table_th_actions#}</td>
</tr>
</thead>
<tbody>
{foreach from=$works item=work}
<tr>
<td align="center">
<strong class="code">{$work.id}</strong>
</td>
<td>
<a class="topDir" title="{#mod_main_table_btn_edit#}" href="index.php?do=modules&action=modedit&mod=workdocs&moduleaction=edit&work_id={$work.id}&cp={$sess}"><strong>{$work.title|escape}</strong></a>
{if $work.description}<br><small>{$work.description}</small>{/if}
</td>
<td align="center" class="col-time">
{if $work.last_run}<span class="date_text dgrey">{$work.last_run|date_format:$TIME_FORMAT|pretty_date}</span>{/if}
</td>
<td align="center">
<strong class="code">
{foreach from=$rubrics item=rubric}
{if $work.rubric_id == $rubric.Id}{$rubric.rubric_title|escape}{/if}
{/foreach}
</strong>
</td>
<td width="1%" align="center">
<a class="topDir icon_sprite ico_start" title="{#mod_main_table_btn_run#}" href="index.php?do=modules&action=modedit&mod=workdocs&moduleaction=run&work_id={$work.id}&cp={$sess}"></a>
</td>
<td width="1%" align="center">
<a class="topDir icon_sprite ico_navigation" title="{#mod_main_table_btn_logs#}" href="index.php?do=modules&action=modedit&mod=workdocs&moduleaction=log&work_id={$work.id}&cp={$sess}"></a>
</td>
<td width="1%" align="center">
<a class="topDir icon_sprite ico_setting" title="{#mod_main_table_btn_settings#}" href="index.php?do=modules&action=modedit&mod=workdocs&moduleaction=edit&work_id={$work.id}&cp={$sess}"></a>
</td>
<td width="1%" align="center">
<a class="topDir icon_sprite ico_delete Delete" title="{#mod_main_table_btn_del#}" href="index.php?do=modules&action=modedit&mod=workdocs&moduleaction=del&work_id={$work.id}&cp={$sess}"></a>
</td>
</tr>
{/foreach}
{else}
<tr>
<td align="center" colspan="7">
<ul class="messages">
<li class="highlight yellow">{#mod_main_table_no_records#}</li>
</ul>
</td>
</tr>
{/if}
</tbody>
</table>
</div>
<div id="tab2" class="tab_content" style="display: none;">
<form id="addNewForm" method="post" action="index.php?do=modules&action=modedit&mod=workdocs&moduleaction=new&cp={$sess}" class="mainForm">
<table cellpadding="0" cellspacing="0" width="100%" class="tableStatic">
<col width="300">
<col>
<tr>
<td>{#mod_main_table_th_name#}</td>
<td><input name="title" type="text" id="title" value="" placeholder="" style="width: 400px" autocomplete="off"></td>
</tr>
<tr>
<td>{#mod_main_table_th_desc#}</td>
<td><input name="description" type="text" id="description" value="" placeholder="" autocomplete="off"></td>
</tr>
<tr>
<td>{#mod_main_table_th_rubdocs#}</td>
<td>
<select id="rubric_id" name="rubric_id" class="mousetrap">
<option value="">{#mod_main_table_th_selrub#}</option>
{foreach from=$rubrics item=rubric}
<option value="{$rubric.Id}">{$rubric.rubric_title|escape}</option>
{/foreach}
</select>
</td>
</tr>
<tr>
<td colspan="2">
<button type="submit" class="basicBtn AddWork">{#mod_main_table_btn_add#}</button>
</td>
</tr>
</table>
</form>
</div>
</div>
<div class="fix"></div>
</div>
<script type="text/javascript" src="{$ABS_PATH}modules/workdocs/js/workdocs.js"></script>
<script type="text/javascript" language="JavaScript">
var del_confirm = '{#mess_del_confirm#}',
del_title = '{#mess_del_title#}',
clear_confirm = '{#mess_clear_confirm#}',
clear_title = '{#mess_clear_title#}',
error_mesage_rubric_id = '{#mess_error_mesage_rubric_id#}',
error_header_rubric_id = '{#mess_error_header_rubric_id#}';
{literal}
$(document).ready(function() {
"use strict";
ModuleWorkDocs.init();
ModuleWorkDocs.index();
});
{/literal}
</script>

146
admin/run.tpl

@ -0,0 +1,146 @@
<div class="title">
<h5>{#mod_title#}</h5>
</div>
<div class="widget" style="margin-top: 0px;">
<div class="body">
{#mod_description#}
</div>
</div>
<div class="breadCrumbHolder module">
<div class="breadCrumb module">
<ul>
<li class="firstB"><a href="index.php" title="{#MAIN_PAGE#}">{#MAIN_PAGE#}</a></li>
<li><a href="index.php?do=modules&cp={$sess}">{#MODULES_SUB_TITLE#}</a></li>
<li><a href="index.php?do=modules&action=modedit&mod=workdocs&moduleaction=1&cp={$sess}">{#mod_title#}</a></li>
<li>{#mod_run_breadcrumbs#}</li>
<li>{$work.title}</li>
</ul>
</div>
</div>
<div id="blockContinue" class="widget first mainForm" {if $work.last_count == 0}style="display: none;"{/if}>
<div class="rowElem">
<div id="btnBlockNew" class="saveBtn" {if !$diff}style="display: none;"{/if}>
<button class="button redBtn btnStartNew" style="width: 100%; display: inline-block; line-height: 30px; height: 30px;">{#mod_run_btn_repeat#}</button>
</div>
<div id="btnBlockWork" class="saveBtn" {if $diff}style="display: none;"{/if}>
<button class="button blueBtn btnStart" style="width: 50%; display: inline-block; line-height: 30px; height: 30px;">{#mod_run_btn_continue#}</button>
<button class="button redBtn btnStartNew" style="width: 50%; display: inline-block; line-height: 30px; height: 30px;">{#mod_run_btn_repeat#}</button>
</div>
</div>
</div>
<div id="blockRun" class="widget first mainForm"{if $work.last_count > 0}style="display: none;"{/if}>
<div class="rowElem">
<div class="saveBtn">
<button class="button blueBtn btnStartNew" style="width: 100%; display: block; line-height: 30px; height: 30px;">{#mod_run_btn_start#}</button>
</div>
</div>
</div>
<div id="stepBlock" data-work="{$work_id}" data-run="{$work.type}" class="widget first">
<div class="head">
<h5 class="iFrames">{#mod_run_header_progress#}</h5>
<div class="num hideBtn" {if ! $work_id}style="display: none"{/if}>
<a class="basicNum topDir" href="index.php?do=modules&action=modedit&mod=workdocs&moduleaction=edit&rubric_id={$rubric_id}&work_id={$work_id}&cp={$sess}">{#mod_run_header_btn_sett#}</a>
</div>
</div>
<div class="body">
<h6 id="header">{#mod_run_header_search_docs#}</h6>
<div>
{#mod_run_search_finded#} <span id="allRecords">{$count}</span>
<br>
{#mod_run_search_ready#} <span id="readyRecords">{if $work.last_count}{$work.last_count - 1}{else}0{/if}</span>
</div>
<div id="progressbar" style="display: block; clear: both; margin-top: 10px;"></div>
<div id="procents" style="text-align: center; margin-top: 10px; font-weight: 600;">0%</div>
<div id="delay" class="highlight yellow" style="text-align: center; margin-top: 10px;">
{#mod_run_search_no_data#}
</div>
<div id="saveTime" style="text-align: center; margin-top: 10px;"></div>
<div id="runData" data-rubric-id="{$rubric_id}" data-work-id="{$work_id}" data-records-counts="{$count}" data-records-start="{if $work.last_count}{$work.last_count - 1}{else}0{/if}"></div>
</div>
<div class="rowElem logDiv" style="display: none;">
<div class="saveBtn">
<a href="cp={$sess}" class="button greyishBtn btnLogs" style="text-align: center; width: 100%; display: block; line-height: 20px; height: 20px;">{#mod_run_btn_see_log#}</a>
</div>
</div>
</div>
<div id="showLog" class="widget first" {if $work.last_count == 0}style="display: none"{/if}>
<div class="rowElem">
<div class="saveBtn">
<a href="index.php?do=modules&action=modedit&mod=workdocs&moduleaction=log&work_id={$work_id}&cp={$sess}" class="button greyishBtn btnLogs" style="text-align: center; width: 100%; display: block; line-height: 20px; height: 20px; padding: 5px 0;">{#mod_run_btn_see_log#}</a>
</div>
</div>
</div>
{if $work.show_logs}
<div id="stepDocs" class="widget first">
<div class="head">
<h5 class="iFrames">{#mod_run_tbl_log#}</h5>
</div>
<table id="logTable" cellpadding="0" cellspacing="0" width="100%" class="tableStatic mainForm">
<col width="30" />
<col />
<col width="450" />
<thead>
<tr>
<td>{#mod_run_tbl_log_id#}</td>
<td>{#mod_run_tbl_log_name#}</td>
<td>{#mod_run_tbl_log_log#}</td>
</tr>
</thead>
{if $work.last_count}
<tbody>
</tbody>
{else}
<tr id="noRecords">
<td align="center" colspan="3">
<ul class="messages">
<li class="highlight yellow">{#mod_run_tbl_log_log_no#}</li>
</ul>
</td>
</tr>
{/if}
</table>
</div>
{/if}
<script type="text/javascript" src="{$ABS_PATH}modules/workdocs/js/workdocs.js"></script>
{literal}
<script type="text/javascript" language="JavaScript">
var allRecords = $('#allRecords').html(), // Общее кол-во
readyRecords = $('#readyRecords'), // Выполнено записей
logTable = $('#logTable'), // Таблица с логами
saveTime = $('#saveTime'), // Время обработки
runData = $('#runData'), // Все для запуска
progressbar = $('#progressbar'), // Прогрессбар
procents = $('#procents'), // Прогрессбар
limitSql = parseInt(runData.data('records-start'));
$(document).ready(function() {
"use strict";
ModuleWorkDocs.init();
ModuleWorkDocs.run();
});
</script>
{/literal}

838
class/class.php

@ -0,0 +1,838 @@
<?php
class WorkDocs
{
//-- Templates directory
public static $tpl_dir;
/* ---------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------- */
/*
|-----------------------------------------------------------------------------------------------------------------------
| _json
|-----------------------------------------------------------------------------------------------------------------------
|
| Return array in JSON format
|
*/
public static function _json ($data, $exit = false)
{
header("Content-Type: application/json;charset=utf-8");
$json = json_encode($data);
if ($json === false)
{
$json = json_encode(array("jsonError", json_last_error_msg()));
if ($json === false)
$json = '{"jsonError": "unknown"}';
http_response_code(500);
}
echo $json;
if ($exit)
exit;
}
private static function _get_all_rubrics ()
{
global $AVE_DB;
$sql = "
SELECT
Id,
rubric_title
FROM
" . PREFIX . "_rubrics
ORDER BY rubric_position ASC
";
$sql = $AVE_DB->Query($sql);
$rubrics = [];
while ($rub = $sql->FetchAssocArray())
array_push($rubrics, $rub);
return $rubrics;
}
private static function _get_rubric ($rubric_id = null)
{
global $AVE_DB;
$rubric_id = (isset($_REQUEST['rubric_id']) ? (int)$_REQUEST['rubric_id'] : $rubric_id);
$sql = "
SELECT
*
FROM
" . PREFIX . "_rubrics
WHERE
Id = {$rubric_id}
LIMIT 0,1
";
$sql = $AVE_DB->Query($sql);
return $sql->FetchAssocArray();
}
private static function _get_rubric_fields ($rubric_id = null)
{
global $AVE_DB, $AVE_Template;
$rubric_id = (isset($_REQUEST['rubric_id']) ? (int)$_REQUEST['rubric_id'] : $rubric_id);
// Поля
$sql = "
SELECT
a.*,
b.group_title,
b.group_description,
b.group_position
FROM
" . PREFIX . "_rubric_fields AS a
LEFT JOIN
" . PREFIX . "_rubric_fields_group AS b
ON a.rubric_field_group = b.Id
WHERE
a.rubric_id = '" . $rubric_id . "'
ORDER BY
b.group_position ASC, a.rubric_field_position ASC
";
$sql = $AVE_DB->Query($sql);
$fields_list = [];
while ($row = $sql->FetchRow())
{
$group_id = ($row->rubric_field_group) ? $row->rubric_field_group : 0;
$fields_list[$group_id]['group_position'] = ($row->group_position) ? $row->group_position : 100;
$fields_list[$group_id]['group_title'] = $row->group_title;
$fields_list[$group_id]['group_description'] = $row->group_description;
$fields_list[$group_id]['fields'][$row->Id]['Id'] = $row->Id;
$fields_list[$group_id]['fields'][$row->Id]['rubric_id'] = $row->rubric_id;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_group'] = $row->rubric_field_group;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_alias'] = $row->rubric_field_alias;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_title'] = $row->rubric_field_title;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_type'] = $row->rubric_field_type;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_numeric'] = $row->rubric_field_numeric;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_default'] = $row->rubric_field_default;
$fields_list[$group_id]['fields'][$row->Id]['rubric_field_search'] = $row->rubric_field_search;
}
$fields_list = msort($fields_list, 'group_position');
$AVE_Template->assign('groups_count', count($fields_list));
$AVE_Template->assign('fields_list', $fields_list);
$AVE_Template->assign('field_array', get_field_type());
}
private static function _get_work ($work_id = null)
{
global $AVE_DB;
$work_id = (isset($_REQUEST['work_id']) ? (int)$_REQUEST['work_id'] : $work_id);
$sql = "
SELECT
*
FROM
" . PREFIX . "_module_workdocs
WHERE
id = {$work_id}
LIMIT 0,1
";
$sql = $AVE_DB->Query($sql);
return $sql->FetchAssocArray();
}
private static function _get_works ()
{
global $AVE_DB;
$sql = "
SELECT
*
FROM
" . PREFIX . "_module_workdocs
";
$sql = $AVE_DB->Query($sql);
$works = [];
while ($work = $sql->FetchAssocArray())
array_push($works, $work);
return $works;
}
private static function _get_num_docs ($rubric_id = null)
{
global $AVE_DB;
$rubric_id = (isset($_REQUEST['rubric_id']) ? (int)$_REQUEST['rubric_id'] : $rubric_id);
$sql = "
SELECT
count(Id)
FROM
" . PREFIX . "_documents
WHERE
rubric_id = {$rubric_id}
";
$sql = $AVE_DB->Query($sql);
return $sql->GetCell();
}
private static function _get_document ($doc_id = null)
{
if (! is_numeric($doc_id) OR $doc_id < 1)
return false;
$data = get_document($doc_id);
$fields = get_document_fields ($doc_id);
foreach ($fields AS $k => $v)
if (is_numeric($k))
$data['feld'][$k] = self::_field_type_value($v);
unset ($fields);
return $data;
}
private static function _field_type_value ($data = [])
{
if (empty($data))
return false;
$func = 'get_field_' . $data['rubric_field_type'];
if (! is_callable($func))
$func = 'get_field_default';
$field_value = $func($data['field_value'], 'api', $data['rubric_field_id'], null, null, $x, null, null, null, $data['rubric_field_default']);
return $field_value;
}
private static function _set_first_start ($work_id)
{
global $AVE_DB;
if (! $work_id)
return false;
$sql = "
DELETE FROM
" . PREFIX . "_module_workdocs_logs
WHERE
work_id = {$work_id}
";
$AVE_DB->Query($sql);
$sql = "
UPDATE
" . PREFIX . "_module_workdocs
SET
last_run = '" . time() . "',
last_count = 0
WHERE
id = {$work_id}
";
$AVE_DB->Query($sql);
return true;
}
private static function _save_logs ($work_id, $document_id, $document_title, $rubric_id, $document_logs, $limit)
{
global $AVE_DB;
$document_title = htmlspecialchars($document_title, ENT_QUOTES);
if ($document_logs)
{
$sql = "
INSERT INTO
" . PREFIX . "_module_workdocs_logs
SET
`work_id` = '{$work_id}',
`rubric_id` = '{$rubric_id}',
`document_id` = '{$document_id}',
`document_title` = '{$document_title}',
`last_run` = '" . time() . "',
`logs` = '" . serialize($document_logs) . "'
";
$AVE_DB->Query($sql);
}
$sql = "
UPDATE
" . PREFIX . "_module_workdocs
SET
last_count = '" . ($limit + 1) . "'
WHERE
id = '{$work_id}'
";
$AVE_DB->Query($sql);
return true;
}
private static function _doc_save ($document_id, $rubric_id, $data, $code, $revisions, $logs)
{
include_once BASE_DIR . '/class/class.docs.php';
$AVE_Document = new AVE_Document();
$document_id = $AVE_Document->documentSave($rubric_id, $document_id, $data, false, $code, $revisions, $logs, false);
return $document_id;
}
private static function _get_logs_json ($work_id = null)
{
global $AVE_DB;
$work = self::_get_work($work_id);
$where = '';
switch ($_REQUEST['iSortCol_0'])
{
case '0':
$order = 'ORDER BY document_id ';
break;
case '1':
$order = 'ORDER BY document_title ';
break;
case '2':
$order = 'ORDER BY last_run ';
break;
case '3':
$order = 'ORDER BY logs ';
break;
}
$order .= $_REQUEST['sSortDir_0'];
$start = $_REQUEST['iDisplayStart'] ? (int)$_REQUEST['iDisplayStart'] : 0;
$finish = $_REQUEST['iDisplayLength'] ? (int)$_REQUEST['iDisplayLength'] : 40;
if (isset($_REQUEST['sSearch']) && $_REQUEST['sSearch'] != '')
{
$where = "AND (document_id LIKE '%{$_REQUEST['sSearch']}%'";
$where .= " OR document_title LIKE '%{$_REQUEST['sSearch']}%'";
$where .= " OR last_run LIKE '%{$_REQUEST['sSearch']}%'";
$where .= " OR logs LIKE '%{$_REQUEST['sSearch']}%')";
}
$sql = "
SELECT SQL_CALC_FOUND_ROWS
*
FROM
" . PREFIX . "_module_workdocs_logs
WHERE
work_id = '{$work_id}'
{$where}
{$order}
LIMIT {$start},{$finish}
";
$sql = $AVE_DB->Query($sql);
$num = $AVE_DB->GetFoundRows();
$output = [
'sEcho' => (int)$_REQUEST['sEcho'],
'iTotalRecords' => $num,
'iTotalDisplayRecords' => $num,
'aaData' => []
];
while ($log = $sql->FetchAssocArray())
{
$output['aaData'][] = [
'<a title="Edit" href="index.php?do=docs&action=edit&rubric_id='. $work['rubric_id'] .'&Id='. $log['document_id'] .'&cp='.SESSION.'" target="_blank">'. $log['document_id'] .'</a>',
'<a title="Show" href="/index.php?id='. $log['document_id'] .'" target="_blank"><strong>' . $log['document_title'] . '</strong></a>',
'<span class="date_text dgrey">' . translate_date(strftime(TIME_FORMAT, $log['last_run'])) . '</span>',
'<small>' . implode('<br>', unserialize($log['logs'])) . '</small>'
];
}
return $output;
}
public static function _clear_text ($string = null, $span = false)
{
// Убираем пробелы начало/конец
$string = trim($string);
// Замена <br>
$replace = [
'<br />' => '<br>',
'<br/>' => '<br>'
];
$string = str_replace(array_keys($replace), array_values($replace), $string);
// RegExp
$expression = [
// Убираем пустые теги
'~<(p|span)>(?>\s+|&nbsp;|(?R))*</\1>~' => '',
// Убираем стили из тегов
'/(<[^>]+) style=".*?"/i' => '$1',
// Убираем двойные пробелы
'/\s{2,}/' => ' ',
// Убираем переходы на новую строку
'/[\t\n]/' => ' ',
// Убираем пустые теги
'/<(\w+)\b(?:\s+[\w\-.:]+(?:\s*=\s*(?:"[^"]*"|"[^"]*"|[\w\-.:]+))?)*\s*\/?>\s*<\/\1\s*>/' => ''
];
// Очищаем текст по условиям
$string = preg_replace(array_keys($expression), array_values($expression), $string);
// Убираем span
if ($span)
{
$replace = [
'<span>' => '',
'</span>' => ''
];
$string = str_replace(array_keys($replace), array_values($replace), $string);
}
// Повторно проходимся по условиям
$string = preg_replace(array_keys($expression), array_values($expression), $string);
// Убираем пробелы начало/конец
$string = trim($string);
return $string;
}
public static function _is_image ($path = null)
{
if (@is_array(getimagesize($path)))
return true;
return false;
}
public static function _if_exists ($path = null)
{
if (file_exists($path))
return true;
return false;
}
public static function _link_exists ($string = null)
{
preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $string, $match);
return $match[0];
}
/* ---------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------- */
public static function mainPage ()
{
global $AVE_Template;
$AVE_Template->assign('works', self::_get_works());
$AVE_Template->assign('rubrics', self::_get_all_rubrics());
$AVE_Template->assign('content', $AVE_Template->fetch(self::$tpl_dir . 'main.tpl'));
}
public static function editWork ()
{
global $AVE_Template;
$work_id = (isset($_REQUEST['work_id']) ? (int)$_REQUEST['work_id'] : '');
$rubric_id = (isset($_REQUEST['rubric_id']) ? (int)$_REQUEST['rubric_id'] : '');
if (! $work_id)
{
$work = [
'title' => (isset($_REQUEST['title']) ? $_REQUEST['title'] : 'Без названия'),
'description' => (isset($_REQUEST['description']) ? $_REQUEST['description'] : ''),
'rubric_id' => $rubric_id
];
$AVE_Template->assign('work', $work);
}
else
{
$work = self::_get_work();
$rubric_id = $work['rubric_id'];
}
self::_get_rubric_fields($rubric_id);
$AVE_Template->assign('work', $work);
$AVE_Template->assign('work_id', $work_id);
$AVE_Template->assign('rubric', self::_get_rubric($rubric_id));
$AVE_Template->assign('rubric_id', $rubric_id);
$AVE_Template->assign('rubrics', self::_get_all_rubrics());
$AVE_Template->assign('content', $AVE_Template->fetch(self::$tpl_dir . 'edit.tpl'));
}
public static function saveWork ()
{
global $AVE_DB, $AVE_Template;
$work_id = (int)$_REQUEST['work_id'];
if (! $work_id)
{
$sql = "
INSERT INTO
" . PREFIX . "_module_workdocs
SET
title = '" . $_REQUEST['title'] . "',
description = '" . $_REQUEST['description'] . "',
rubric_id = '" . (int)$_REQUEST['rubric_id'] . "',
save_enable = '" . ($_REQUEST['save_enable'] ? '1' : '0') . "',
code_enable = '" . ($_REQUEST['code_enable'] ? '1' : '0') . "',
revisions_enable = '" . ($_REQUEST['revisions_enable'] ? '1' : '0') . "',
logs_enable = '" . ($_REQUEST['logs_enable'] ? '1' : '0') . "',
self_sql = '" . $_REQUEST['self_sql'] . "',
code_before = '" . $_REQUEST['code_before'] . "',
code_after = '" . $_REQUEST['code_after'] . "'
";
$sql = $AVE_DB->Query($sql);
$work_id = $AVE_DB->InsertId();
}
else
{
$sql = "
UPDATE
" . PREFIX . "_module_workdocs
SET
title = '" . $_REQUEST['title'] . "',
description = '" . $_REQUEST['description'] . "',
save_enable = '" . ($_REQUEST['save_enable'] ? '1' : '0') . "',
code_enable = '" . ($_REQUEST['code_enable'] ? '1' : '0') . "',
revisions_enable = '" . ($_REQUEST['revisions_enable'] ? '1' : '0') . "',
logs_enable = '" . ($_REQUEST['logs_enable'] ? '1' : '0') . "',
self_sql = '" . $_REQUEST['self_sql'] . "',
code_before = '" . $_REQUEST['code_before'] . "',
code_after = '" . $_REQUEST['code_after'] . "'
WHERE
id = '" . $work_id . "'
";
$sql = $AVE_DB->Query($sql);
}
$return = [
'success' => $sql ? true : false,
'work_id' => $work_id,
'message' => $sql ? $AVE_Template->get_config_vars('mod_edit_save_succes_t') : $AVE_Template->get_config_vars('mod_edit_save_error_t'),
'header' => $sql ? $AVE_Template->get_config_vars('mod_edit_save_succes_h') : $AVE_Template->get_config_vars('mod_edit_save_error_h'),
'theme' => $sql ? 'accept' : 'error',
];
if (isAjax())
{
self::_json($return, true);
}
else
{
$location = $work_id
? 'index.php?do=modules&action=modedit&mod=workdocs&moduleaction=1&cp=' . SESSION
: 'index.php?do=modules&action=modedit&mod=workdocs&moduleaction=1&cp=' . SESSION;
header('Location:' . $location);
exit;
}
}
public static function runWork ()
{
global $AVE_Template;
$work_id = (int)$_REQUEST['work_id'];
$work = self::_get_work($work_id);
$rubric_id = $work['rubric_id'];
$counts = self::_get_num_docs($rubric_id);
$diff = ($counts == $work['last_count']);
$AVE_Template->assign('work_id', $work_id);
$AVE_Template->assign('work', $work);
$AVE_Template->assign('diff', $diff);
$AVE_Template->assign('rubric_id', $rubric_id);
$AVE_Template->assign('count', $counts);
$AVE_Template->assign('content', $AVE_Template->fetch(self::$tpl_dir . 'run.tpl'));
}
public static function stepOne ()
{
global $AVE_DB, $AVE_Template;
Debug::startTime('step');
// Логи
$document_logs = [];
// Лимит
$limit = (isset($_REQUEST['limit']) ? (int)$_REQUEST['limit'] : 0);
// ID Работы
$work_id = (int)$_REQUEST['work_id'];
// Если не получено, то
if (! $work_id)
{
$return = ['success' => false];
self::_json($return, true);
}
// Получаем настройки
$work = self::_get_work($work_id);
// ID рубрики
$rubric_id = (int)$work['rubric_id'];
// Если первый документ, очищаем логи и ставим время обхода
if ($limit == 0)
self::_set_first_start($work_id);
// Свой SQL, код
if ($work['self_sql'])
eval (' ?>' . $work['self_sql'] . '<?'.'php ');
// SQL запрос, на получение ID документа
if (! isset($sql))
{
$sql = "
SELECT
Id
FROM
" . PREFIX . "_documents
WHERE
rubric_id = {$work['rubric_id']}
ORDER BY Id DESC
LIMIT {$limit}, 1;
";
}
// Получаем ID документа
if (! isset($document_id))
$document_id = $AVE_DB->Query($sql)->GetCell();
// Получаем данные документа, включая данные полей
$data = self::_get_document($document_id);
// Выполняем код перед сохранением документа
if ($work['code_before'] > '')
eval (' ?>' . $work['code_before'] . '<?'.'php ');
// Сохранение документа, если стоит галочка и есть данные
if ($work['save_enable'] == 1 && $data)
$save_id = self::_doc_save($document_id, $rubric_id, $data, (bool)$work['code_enable'], (bool)$work['revisions_enable'], (bool)$work['logs_enable']);
// Выполняем код после сохранением документа
if ($work['code_after'] > '')
eval (' ?>' . $work['code_after'] . '<?'.'php ');
// Сохраняем логи
self::_save_logs($work_id, $document_id, $data['document_title'], $rubric_id, $document_logs, $limit);
// Ответ
$return = [
'success' => true,
'time' => Debug::endTime('step'),
'limit' => $limit + 1,
'document_id' => $document_id,
'rubric_id' => $rubric_id,
'document_title' => $data['document_title'],
'document_alias' => $data['document_alias'],
'document_log' => implode('<br>', $document_logs)
];
self::_json($return, true);
}
public static function logWork ()
{
global $AVE_Template;
$work_id = (int)$_REQUEST['work_id'];
$AVE_Template->assign('work_id', $work_id);
$AVE_Template->assign('work', self::_get_work($work_id));
$AVE_Template->assign('content', $AVE_Template->fetch(self::$tpl_dir . 'log.tpl'));
}
public static function logJson ()
{
$work_id = (int)$_REQUEST['work_id'];
$output = self::_get_logs_json($work_id);
self::_json($output, true);
}
public static function delWork ()
{
global $AVE_DB;
$work_id = (int)$_REQUEST['work_id'];
$location = 'index.php?do=modules&action=modedit&mod=workdocs&moduleaction=1&cp=' . SESSION;
if (! $work_id)
{
header('Location:' . $location);
exit;
}
$sql = "
DELETE FROM
" . PREFIX . "_module_workdocs
WHERE
id = '{$work_id}'
";
$AVE_DB->Query($sql);
$sql = "
DELETE FROM
" . PREFIX . "_module_workdocs_logs
WHERE
work_id = '{$work_id}'
";
$AVE_DB->Query($sql);
header('Location:' . $location);
exit;
}
public static function clearWork ()
{
global $AVE_DB;
$work_id = (int)$_REQUEST['work_id'];
$sql = "
DELETE FROM
" . PREFIX . "_module_workdocs_logs
WHERE
work_id = '{$work_id}'
";
$AVE_DB->Query($sql);
$sql = "
UPDATE
" . PREFIX . "_module_workdocs
SET
last_run = '',
last_count = '0'
WHERE
id = '{$work_id}'
";
$AVE_DB->Query($sql);
$return = [
'success' => true
];
self::_json($return, true);
}
public static function clearWorks ()
{
global $AVE_DB;
$sql = "
TRUNCATE TABLE " . PREFIX . "_module_workdocs_logs
";
$AVE_DB->Query($sql);
$sql = "
UPDATE
" . PREFIX . "_module_workdocs
SET
last_run = '',
last_count = '0'
";
$AVE_DB->Query($sql);
$return = [
'success' => true
];
self::_json($return, true);
}
}

20
css/workdocs.css

@ -0,0 +1,20 @@
small {
font-size: 11px;
color: #687282;
}
tr.odd {
background-color: #fff;
}
tr.even {
background-color: #edf2f7;
}
tr.odd td.sorting_1 {
background-color: #E3EBF2;
}
tr.even td.sorting_1 {
background-color: #EDF2F7;
}

19
info.php

@ -0,0 +1,19 @@
<?php
if (! defined('BASE_DIR'))
exit;
$module = [
'ModuleSysName' => 'workdocs',
'ModuleVersion' => '1.0',
'ModuleAutor' => 'M@d D3n (support@ave-cms.ru)',
'ModuleCopyright' => '&copy; 2007-' . date('Y') . ' AVE.cms',
'ModuleIsFunction' => false,
'ModuleTemplate' => false,
'ModuleAdminEdit' => true,
'ModuleFunction' => 'mod_workdocs',
'ModuleTag' => null,
'ModuleTagLink' => null,
'ModuleAveTag' => null,
'ModulePHPTag' => null,
'ModuleFieldFile' => null
];

360
js/workdocs.js

@ -0,0 +1,360 @@
var ModuleWorkDocs = {
initialized: false,
init: function () {
if (this.initialized)
return;
this.initialized = true;
},
index: function () {
this.addWork();
this.deleteBtn();
this.clearLogs();
},
edit: function () {
this.saveBtn();
this.MouseTrap();
},