index.php 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491
  1. <?php
  2. if (cfr('VOLS')) {
  3. /**
  4. * Класс:
  5. */
  6. class VOLS {
  7. /* Private variablesЖ */
  8. private $html;
  9. private $config = array();
  10. private $polylines = '';
  11. private $placemarks = '';
  12. /* Names of forms: */
  13. const FORM_ADD = 'form_add';
  14. const FORM_EDIT = 'form_edit';
  15. /* URLs: */
  16. const URL_HOME = '?module=vols&item=map&action=show';
  17. const URL_MAP_SHOW = '?module=vols&item=map&action=show';
  18. const URL_MAP_EDIT = '?module=vols&item=map&action=edit';
  19. const URL_MARK_TYPES_LIST = '?module=vols&item=mark_type&action=list';
  20. const URL_MARK_TYPE_EDIT = '?module=vols&item=mark_type&action=edit&id=';
  21. const URL_MARK_TYPE_DEL = '?module=vols&item=mark_type&action=delete&id=';
  22. const URL_MARK_TYPE_ADD = '?module=vols&item=mark_type&action=add';
  23. const URL_MARKS_LIST = '?module=vols&item=mark&action=list';
  24. const URL_MARK_PLACE = '?module=vols&item=mark&action=place&id=';
  25. const URL_MARK_DOCS = '?module=vols&item=mark&action=documents&id=';
  26. const URL_MARK_EDIT = '?module=vols&item=mark&action=edit&id=';
  27. const URL_MARK_DEL = '?module=vols&item=mark&action=delete&id=';
  28. const URL_MARK_ADD = '?module=vols&item=mark&action=add';
  29. const URL_LINES_LIST = '?module=vols&item=line&action=list';
  30. const URL_LINE_PLACE = '?module=vols&item=line&action=place&id=';
  31. const URL_LINE_DOCS = '?module=vols&item=line&action=documents&id=';
  32. const URL_LINE_EDIT = '?module=vols&item=line&action=edit&id=';
  33. const URL_LINE_DEL = '?module=vols&item=line&action=delete&id=';
  34. const URL_LINE_ADD = '?module=vols&item=line&action=add';
  35. const URL_DOC_DOWNLOAD = '?module=vols&item=document&action=download&id=';
  36. const URL_DOC_DELETE = '?module=vols&item=document&action=delete&id=';
  37. /* DB tables: */
  38. const TABLE_DOCS = 'vols_docs';
  39. const TABLE_LINES = 'vols_lines';
  40. const TABLE_MARKS = 'vols_marks';
  41. const TABLE_MARKS_TYPES = 'vols_marks_types';
  42. /* Maps` constants: */
  43. const MAP_ID = 'ymaps';
  44. const MAP_VAR = 'yandexMaps';
  45. const MAP_CLUSTERER = 'clusterer';
  46. const MAP_LINES_ARR = 'polylines';
  47. const MAP_MARKS_ARR = 'placemarks';
  48. /**
  49. * Constructor. Loads `ymaps.ini` configuration file data
  50. *
  51. * @return boolean true
  52. */
  53. public function __construct() {
  54. $this->config = parse_ini_file(CONFIG_PATH . 'ymaps.ini', true);
  55. return true;
  56. }
  57. /**
  58. * Generates HTML-code of Yandex.Maps control buttons
  59. *
  60. * @return string HTML-code of Yandex.Maps control buttons
  61. */
  62. private function map_controls() {
  63. // Controls:
  64. $this->html .= wf_Link(self::URL_MARK_TYPES_LIST, __('Types of marks'), false, 'ubButton');
  65. $this->html .= wf_Link(self::URL_MARKS_LIST, __('VOLS marks'), false, 'ubButton');
  66. $this->html .= wf_Link(self::URL_LINES_LIST, __('VOLS lines'), false, 'ubButton');
  67. switch (true) {
  68. case ( strpos($_SERVER['REQUEST_URI'], self::URL_MAP_EDIT) !== false ):
  69. case ( strpos($_SERVER['REQUEST_URI'], self::URL_MARK_PLACE) !== false ):
  70. case ( strpos($_SERVER['REQUEST_URI'], self::URL_LINE_PLACE) !== false ):
  71. $this->html .= wf_Link(self::URL_MAP_SHOW, __('Save'), false, 'ubButton');
  72. break;
  73. default:
  74. $this->html .= wf_Link(self::URL_MAP_EDIT, __('Edit'), false, 'ubButton');
  75. break;
  76. }
  77. $this->html .= wf_delimiter(1);
  78. return $this->html;
  79. }
  80. /**
  81. * Generates HTML-code of Yandex.Maps container with control buttons
  82. *
  83. * @return string HTML-code of Yandex.Maps container
  84. */
  85. private function map_container() {
  86. // Generate control buttons:
  87. $this->map_controls();
  88. // Map container:
  89. $this->html .= wf_tag('div', false, null, 'id="' . self::MAP_ID . '" style="width: 1000; height:800px;"');
  90. $this->html .= wf_tag('div', true);
  91. return $this->html;
  92. }
  93. /**
  94. * Generates Yandex.Maps JavaScript init code
  95. *
  96. * @return string HTML-code of Yandex.Maps ( JavaScript )
  97. */
  98. public function map_init($edit = false) {
  99. global $ubillingConfig;
  100. // Generate map container:
  101. $this->map_container();
  102. $mapsCfg = $ubillingConfig->getYmaps();
  103. $yandexApiKey = @$mapsCfg['YMAPS_APIKEY'];
  104. if ($yandexApiKey) {
  105. $yandexApiKey = '&apikey=' . $yandexApiKey;
  106. } else {
  107. $yandexApiKey = '';
  108. }
  109. $apiUrl = 'https://api-maps.yandex.ru/2.0/';
  110. // Init code:
  111. $this->html .= '
  112. <script src="' . $apiUrl . '?load=package.full&lang=' . $this->config['LANG'] . $yandexApiKey . '" type="text/javascript"></script>
  113. <script type="text/javascript">
  114. ymaps.ready(init);
  115. function init () {
  116. var ' . self::MAP_MARKS_ARR . ' = new Array();
  117. var ' . self::MAP_LINES_ARR . ' = new Array();
  118. var ' . self::MAP_CLUSTERER . ' = new ymaps.Clusterer({
  119. gridSize: 100,
  120. clusterDisableClickZoom: false
  121. });
  122. var ' . self::MAP_VAR . ' = new ymaps.Map("' . self::MAP_ID . '", {
  123. zoom: ' . $this->config['ZOOM'] . ',
  124. type: "yandex#' . $this->config['TYPE'] . '",
  125. center: [' . (!empty($this->config['CENTER']) ? $this->config['CENTER'] : 'ymaps.geolocation.latitude, ymaps.geolocation.longitude' ) . '],
  126. behaviors: ["default", "scrollZoom"]
  127. }, {
  128. balloonMaxWidth: 250
  129. });
  130. ' . self::MAP_VAR . '.controls
  131. .add("zoomControl")
  132. .add("typeSelector")
  133. .add("mapTools")
  134. .add("searchControl");
  135. // Функция, преобразующая массив с координатами в строку:
  136. function coords_to_string(coords) {
  137. var result = "";
  138. if ( jQuery.isArray(coords) ) {
  139. result = "[ ";
  140. for (var i = 0, l = coords.length; i < l; i++) {
  141. if (i > 0) {
  142. result += ", ";
  143. }
  144. result += coords_to_string(coords[i]);
  145. }
  146. result += " ]";
  147. } else if ( typeof coords == "number" ) {
  148. result = coords.toPrecision(8);
  149. } else if ( coords.toString ) {
  150. result = coords.toString();
  151. }
  152. return result;
  153. }
  154. // Функция, высчитывающая длинну линии:
  155. function polyline_length(coords) {
  156. var distance = 0;
  157. if ( coords.length >= 2) {
  158. for ( var i = 0, l = coords.length - 1; i < l; i++ ) {
  159. distance += ymaps.coordSystem.geo.getDistance(coords[ i ], coords[ i + 1 ]);
  160. }
  161. }
  162. return distance.toFixed(2);
  163. }
  164. // Функция для сохраниения координат в БД:
  165. function placemark_geo_save(id, coords) {
  166. jQuery.ajax({
  167. type: "POST",
  168. url: "' . self::URL_MARK_EDIT . '" + id,
  169. data: {
  170. ' . self::FORM_EDIT . ': {
  171. geo: coords_to_string(coords)
  172. }
  173. }
  174. });
  175. return true;
  176. }
  177. // Функция для сохраниения координат в БД:
  178. function polyline_geo_save(id, coords) {
  179. jQuery.ajax({
  180. type: "POST",
  181. url: "' . self::URL_LINE_EDIT . '" + id,
  182. data: {
  183. ' . self::FORM_EDIT . ': {
  184. geo: coords_to_string(coords),
  185. length: polyline_length(coords)
  186. }
  187. }
  188. });
  189. return true;
  190. }
  191. // Функция для добавления кластера на карту:
  192. function clusterize() {
  193. // Если кластер уже был создан - удаляем:
  194. if (' . self::MAP_CLUSTERER . '.getBounds() != null ) {
  195. ' . self::MAP_CLUSTERER . '.remove(' . self::MAP_MARKS_ARR . ');
  196. ' . self::MAP_VAR . '.geoObjects.remove(' . self::MAP_CLUSTERER . ');
  197. }
  198. // Добавляем элементы в кластер:
  199. ' . self::MAP_CLUSTERER . '.add(' . self::MAP_MARKS_ARR . ');
  200. // Добавляем кластер на карту:
  201. ' . self::MAP_VAR . '.geoObjects.add(' . self::MAP_CLUSTERER . ');
  202. }
  203. ' . $this->show_placemarks($edit) . '
  204. ' . $this->show_polylines() . '
  205. // Размещаем все линии на карте:
  206. jQuery.map( ' . self::MAP_LINES_ARR . ' , function( polyline ) {
  207. ' . self::MAP_VAR . '.geoObjects.add( polyline );
  208. });
  209. clusterize();
  210. ';
  211. if ($edit) {
  212. $this->html .= '
  213. jQuery.map( ' . self::MAP_MARKS_ARR . ' , function( placemark ) {
  214. placemark.events.add(\'dragend\', function ( e ) {
  215. var target = e.get(\'target\');
  216. var coords = target.geometry.getCoordinates();
  217. placemark_geo_save(target.properties.get(\'id\'), coords);
  218. clusterize();
  219. });
  220. placemark.events.add(\'contextmenu\', function ( e ) {
  221. var target = e.get(\'target\');
  222. var coords = new Array();
  223. ' . self::MAP_CLUSTERER . '.remove(target);
  224. placemark_geo_save(target.properties.get(\'id\'), coords);
  225. });
  226. });
  227. jQuery.map( ' . self::MAP_LINES_ARR . ' , function( polyline ) {
  228. polyline.editor.startEditing();
  229. polyline.events.add(\'geometrychange\', function ( e ) {
  230. var target = e.get(\'target\');
  231. var coords = target.geometry.getCoordinates();
  232. polyline_geo_save(target.properties.get(\'id\'), coords);
  233. });
  234. polyline.editor.options.set({
  235. menuManager: function ( menuItems, model ) {
  236. menuItems.push({
  237. id: \'RemoveFromMap\',
  238. title: \'' . __('Remove from map') . '\',
  239. onClick: function ( graphicsObject, pointIndex, coordPath ) {
  240. var coords = new Array();
  241. polyline_geo_save(polyline.properties.get(\'id\'), coords);
  242. ' . self::MAP_VAR . '.geoObjects.remove( polyline );
  243. graphicsObject.stopEditing();
  244. }
  245. });
  246. return menuItems;
  247. }
  248. });
  249. });
  250. ';
  251. }
  252. return $this->html . '}
  253. </script>
  254. ';
  255. }
  256. /**
  257. * Places closures on the map, whitch have coords in DB. If
  258. * $edit_mode was setted to `true` you will be abled to edit
  259. * position of any placemark. All changes of position will be
  260. * written to database.
  261. *
  262. * @param boolean $edit_mode Is edit mode enabled?
  263. * @return string Javascript code of placemarks
  264. */
  265. private function show_placemarks($draggable = false) {
  266. // Take a closures list from database:
  267. $query = "
  268. SELECT
  269. `" . self::TABLE_MARKS . "`.`id`,
  270. `" . self::TABLE_MARKS . "`.`number`,
  271. `" . self::TABLE_MARKS . "`.`placement`,
  272. `" . self::TABLE_MARKS . "`.`description`,
  273. `" . self::TABLE_MARKS_TYPES . "`.`type`,
  274. `" . self::TABLE_MARKS_TYPES . "`.`model`,
  275. `" . self::TABLE_MARKS_TYPES . "`.`icon_color`,
  276. `" . self::TABLE_MARKS_TYPES . "`.`icon_style`,
  277. `" . self::TABLE_MARKS . "`.`geo`
  278. FROM `" . self::TABLE_MARKS . "`
  279. LEFT JOIN `" . self::TABLE_MARKS_TYPES . "`
  280. ON `" . self::TABLE_MARKS_TYPES . "`.`id` = `" . self::TABLE_MARKS . "`.`type_id`
  281. WHERE `" . self::TABLE_MARKS . "`.`geo` != ''
  282. AND `" . self::TABLE_MARKS . "`.`geo` != '[ ]'";
  283. $placemarks = simple_queryall($query);
  284. if (!empty($placemarks)) {
  285. foreach ($placemarks as $placemark) {
  286. // Actions:
  287. $actions = wf_Link(self::URL_MARK_DOCS . $placemark['id'], web_corporate_icon('Documentation'));
  288. $actions = str_replace("\n", null, $actions);
  289. $this->placemarks .= "
  290. " . self::MAP_MARKS_ARR . ".push(
  291. new ymaps.Placemark(" . $placemark['geo'] . ", {
  292. id: " . $placemark['id'] . ",
  293. iconContent: '" . $placemark['number'] . "',
  294. balloonContentHeader: '<i>#" . $placemark['number'] . ": " . $placemark['type'] . " </i>',
  295. balloonContentBody: '<div style=\"text-align: justify; text-indent: 1.5em; margin-top: 5px;\">" . $placemark['description'] . "</div>',
  296. balloonContentFooter: '" . $actions . "',
  297. }, {
  298. draggable: " . ( $draggable ? 'true' : 'false' ) . ",
  299. preset: 'twirl#" . $placemark['icon_color'] . $placemark['icon_style'] . "Icon'
  300. })
  301. );
  302. ";
  303. }
  304. }
  305. return $this->placemarks;
  306. }
  307. /**
  308. * This function enebles "placemark adding mode". It's add `click`
  309. * event handling. After event click coordinates will be added to
  310. * `geo` column of adding placemark ( WHERE `id` = $placemark_id).
  311. * It's add `dragend` event handling too.
  312. *
  313. * @param integer $closure_id
  314. * @return string
  315. */
  316. function place_placemark($id) {
  317. // Take a closures list from database:
  318. $query = "
  319. SELECT
  320. `" . self::TABLE_MARKS . "`.`id`,
  321. `" . self::TABLE_MARKS . "`.`number`,
  322. `" . self::TABLE_MARKS . "`.`placement`,
  323. `" . self::TABLE_MARKS . "`.`description`,
  324. `" . self::TABLE_MARKS_TYPES . "`.`type`,
  325. `" . self::TABLE_MARKS_TYPES . "`.`model`,
  326. `" . self::TABLE_MARKS_TYPES . "`.`icon_color`,
  327. `" . self::TABLE_MARKS_TYPES . "`.`icon_style`,
  328. `" . self::TABLE_MARKS . "`.`geo`
  329. FROM `" . self::TABLE_MARKS . "`
  330. LEFT JOIN `" . self::TABLE_MARKS_TYPES . "`
  331. ON `" . self::TABLE_MARKS_TYPES . "`.`id` = `" . self::TABLE_MARKS . "`.`type_id`
  332. WHERE `" . self::TABLE_MARKS . "`.`id` = '" . $id . "'";
  333. $placemark = simple_query($query);
  334. if (!empty($placemark)) {
  335. // Actions:
  336. $actions = wf_Link(self::URL_MARK_DOCS . $placemark['id'], web_corporate_icon('Documentation'));
  337. $actions = str_replace("\n", null, $actions);
  338. $this->placemarks .= "
  339. " . self::MAP_VAR . ".events.add('click', function (e) {
  340. // Предотвращаем добавление на карту нескольких
  341. // одинаковых меток, при повторном клике:
  342. if ( typeof newPlacemark != 'undefined' ) {
  343. " . self::MAP_VAR . ".geoObjects.remove( newPlacemark );
  344. }
  345. // Размещаем метку на карте:
  346. var coords = e.get('coordPosition');
  347. newPlacemark = new ymaps.Placemark(coords, {
  348. id: " . $placemark['id'] . ",
  349. iconContent: '" . $placemark['number'] . "',
  350. balloonContentHeader: '<i>" . $placemark['type'] . " #" . $placemark['number'] . "</i>',
  351. balloonContentBody: '" . $placemark['description'] . "',
  352. balloonContentFooter: '" . $actions . "'
  353. } , {
  354. draggable: true,
  355. preset: 'twirl#" . $placemark['icon_color'] . $placemark['icon_style'] . "Icon',
  356. });
  357. " . self::MAP_VAR . ".geoObjects.add( newPlacemark );
  358. // Добавляем координаты клика в БД:
  359. placemark_geo_save(" . $placemark['id'] . ", coords);
  360. // Добавляем обработку события перетаскивания:
  361. newPlacemark.events.add('dragend', function (e) {
  362. var target = e.get('target');
  363. var coords = target.geometry.getCoordinates();
  364. placemark_geo_save(" . $placemark['id'] . ", coords);
  365. });
  366. });
  367. ";
  368. }
  369. return true;
  370. }
  371. /**
  372. * Places lines on the map, whitch have coords in DB. If $edit_mode
  373. * was setted to `true` you will be abled to edit geometry of any
  374. * line. All changes of geometry will be written to database.
  375. *
  376. * @param boolean $edit_mode Is edit mode enabled?
  377. * @return string Javascript code of lines
  378. */
  379. function show_polylines() {
  380. // Take a closures list from database:
  381. $query = "SELECT * FROM `" . self::TABLE_LINES . "` WHERE `geo` IS NOT NULL AND `geo` != '[ ]'";
  382. $result = simple_queryall($query);
  383. if (!empty($result)) {
  384. foreach ($result as $line) {
  385. $this->polylines .= "
  386. " . self::MAP_LINES_ARR . ".push(
  387. new ymaps.Polyline(" . $line['geo'] . ", {
  388. id: " . $line['id'] . ",
  389. hintContent: '" . $line['point_start'] . " -> " . $line['point_end'] . ", " . $line['length'] . "'
  390. }, {
  391. strokeColor: '" . str_replace('#', '', trim($line['param_color'])) . "ff',
  392. strokeWidth: " . $line['param_width'] . "
  393. })
  394. );
  395. ";
  396. }
  397. }
  398. return $this->polylines;
  399. }
  400. public function place_polyline($id) {
  401. // Take a lines list from database:
  402. $query = "SELECT * FROM `" . self::TABLE_LINES . "` WHERE `id` = '" . $id . "'";
  403. $polyline = simple_query($query);
  404. if (!empty($polyline)) {
  405. $this->polylines .= "
  406. // Добавляем новую линию:
  407. newPolyline = new ymaps.Polyline( [] , {
  408. id: " . $polyline['id'] . ",
  409. hintContent: '" . $polyline['description'] . "'
  410. }, {
  411. strokeColor: '" . str_replace('#', '', trim($polyline['param_color'])) . "ff',
  412. strokeWidth: " . $polyline['param_width'] . "
  413. });
  414. " . self::MAP_VAR . ".geoObjects.add( newPolyline );
  415. // Добавляем в контекстное меню кнопку удаления всей линии:
  416. newPolyline.editor.options.set({
  417. menuManager: function ( menuItems, model ) {
  418. menuItems.push({
  419. id: 'Cancel',
  420. title: '" . __('Remove from map') . "',
  421. onClick: function ( graphicsObject, pointIndex, coordPath ) {
  422. var coords = new Array();
  423. polyline_geo_save(" . $polyline['id'] . ", coords);
  424. " . self::MAP_VAR . ".geoObjects.remove( newPolyline );
  425. graphicsObject.stopEditing();
  426. }
  427. });
  428. return menuItems;
  429. }
  430. });
  431. newPolyline.editor.startEditing();
  432. newPolyline.editor.startDrawing();
  433. // При `geometrychange` вносим новые координаты в БД:
  434. newPolyline.events.add('geometrychange', function (e) {
  435. var target = e.get('target');
  436. var coords = target.geometry.getCoordinates();
  437. polyline_geo_save(" . $polyline['id'] . ", coords);
  438. });
  439. ";
  440. }
  441. return true;
  442. }
  443. /**
  444. * Get employee list from database
  445. *
  446. * @return array Employee array ( $id => $name )
  447. */
  448. private function get_employee() {
  449. $query = "SELECT `id`, `name` FROM `employee`";
  450. $result = simple_queryall($query);
  451. $return = array();
  452. if (!empty($result)) {
  453. foreach ($result as $employee) {
  454. $return[$employee['id']] = $employee['name'];
  455. }
  456. }
  457. return $return;
  458. }
  459. /**
  460. * Get marks types list from database
  461. *
  462. * @return array Marks types array ( $id => $type )
  463. */
  464. private function get_marks_types() {
  465. $query = "SELECT `id`, `type` FROM `" . self::TABLE_MARKS_TYPES . "`";
  466. $result = simple_queryall($query);
  467. $return = array();
  468. if (!empty($result)) {
  469. foreach ($result as $marks_type) {
  470. $return[$marks_type['id']] = $marks_type['type'];
  471. }
  472. }
  473. return $return;
  474. }
  475. /* MARK TYPES */
  476. /**
  477. * Returns HTML-table, containing existing mark types
  478. *
  479. * @return string HTML-table
  480. */
  481. public function mark_type_list_show() {
  482. // Query marks types & amount of eachs is used:
  483. $query = "SELECT
  484. `" . self::TABLE_MARKS_TYPES . "`.`id`,
  485. `" . self::TABLE_MARKS_TYPES . "`.`type`,
  486. `" . self::TABLE_MARKS_TYPES . "`.`model`,
  487. `" . self::TABLE_MARKS_TYPES . "`.`description`,
  488. `" . self::TABLE_MARKS_TYPES . "`.`icon_color`,
  489. `" . self::TABLE_MARKS_TYPES . "`.`icon_style`,
  490. COUNT(`" . self::TABLE_MARKS . "`.`id`) AS `amount`
  491. FROM `" . self::TABLE_MARKS_TYPES . "`
  492. LEFT JOIN `" . self::TABLE_MARKS . "`
  493. ON `" . self::TABLE_MARKS_TYPES . "`.`id` = `" . self::TABLE_MARKS . "`.`type_id`
  494. GROUP BY `" . self::TABLE_MARKS_TYPES . "`.`id`, `" . self::TABLE_MARKS_TYPES . "`.`type`
  495. ORDER BY `" . self::TABLE_MARKS_TYPES . "`.`id`
  496. ";
  497. $result = simple_queryall($query);
  498. // HTML-table header:
  499. $cells = wf_TableCell(__('ID'));
  500. $cells .= wf_TableCell(__('Type'), 100);
  501. $cells .= wf_TableCell(__('Model'), 150);
  502. $cells .= wf_TableCell(__('Description'));
  503. $cells .= wf_TableCell(__('Quantity'), 50);
  504. $cells .= wf_TableCell(__('Icon'), 125);
  505. $cells .= wf_TableCell(__('Actions'), 50);
  506. $rows = wf_TableRow($cells, 'row2');
  507. // HTML-table content:
  508. if (!empty($result)) {
  509. foreach ($result as $marks_type) {
  510. $cells = wf_TableCell($marks_type['id']);
  511. $cells .= wf_TableCell($marks_type['type']);
  512. $cells .= wf_TableCell($marks_type['model']);
  513. $cells .= wf_TableCell($marks_type['description']);
  514. $cells .= wf_TableCell($marks_type['amount']);
  515. $cells .= wf_TableCell($marks_type['icon_color'] . $marks_type['icon_style']);
  516. // Actions:
  517. $actions = wf_Link(self::URL_MARK_TYPE_EDIT . $marks_type['id'], web_edit_icon());
  518. if ($marks_type['amount'] == 0) {
  519. $actions .= wf_Link(self::URL_MARK_TYPE_DEL . $marks_type['id'], web_delete_icon());
  520. }
  521. $cells .= wf_TableCell($actions);
  522. $rows .= wf_TableRow($cells, 'row3');
  523. }
  524. } else {
  525. $cells = wf_TableCell(__('There is no marks types to show'), null, null, 'colspan="8" align="center"');
  526. $rows .= wf_TableRow($cells, 'row3');
  527. }
  528. // Generate HTML-table:
  529. return wf_TableBody($rows, '100%', '0', 'sortable');
  530. }
  531. /**
  532. * Returns marks type add form
  533. *
  534. * @return string Generated HTML-form
  535. */
  536. public function mark_type_add_form_show() {
  537. // Fill in the inputs:
  538. $inputs = wf_TextInput(self::FORM_ADD . '[type]', 'Type', null, true, '25');
  539. $inputs .= wf_TextInput(self::FORM_ADD . '[model]', 'Model', null, true, '25');
  540. $inputs .= wf_TextInput(self::FORM_ADD . '[description]', 'Description', null, true, '25');
  541. $inputs .= wf_Selector(self::FORM_ADD . '[icon_color]', array(
  542. 'blue' => 'blue',
  543. 'orange' => 'orange',
  544. 'darkblue' => 'darkblue',
  545. 'pink' => 'pink',
  546. 'darkgreen' => 'darkgreen',
  547. 'red' => 'red',
  548. 'darkorange' => 'darkorange',
  549. 'violet' => 'violet',
  550. 'green' => 'green',
  551. 'white' => 'white',
  552. 'grey' => 'grey',
  553. 'yellow' => 'yellow',
  554. 'lightblue' => 'lightblue',
  555. 'brown' => 'brown',
  556. 'night' => 'night',
  557. 'black' => 'black',
  558. ), 'Icon', null, true, '25');
  559. $inputs .= wf_Selector(self::FORM_ADD . '[icon_style]', array(
  560. '' => '',
  561. 'Dot' => 'Dot',
  562. 'Stretchy' => 'Stretchy'
  563. ), 'Icon style', null, true, '25');
  564. $inputs .= wf_Submit('Save', 'ubButton');
  565. // Generate HTML-form:
  566. return wf_Form('', 'POST', $inputs, 'glamour');
  567. }
  568. /**
  569. * Returns marks type edit form
  570. *
  571. * @return string HTML-form
  572. */
  573. public function mark_type_edit_form_show($id) {
  574. // Get current data from database:
  575. $query = "SELECT * FROM `" . self::TABLE_MARKS_TYPES . "` WHERE `id` = '" . $id . "'";
  576. $result = simple_query($query);
  577. // Fill in the inputs:
  578. $inputs = wf_TextInput(self::FORM_EDIT . '[type]', 'Type', $result['type'], true, '25');
  579. $inputs .= wf_TextInput(self::FORM_EDIT . '[model]', 'Model', $result['model'], true, '25');
  580. $inputs .= wf_TextInput(self::FORM_EDIT . '[description]', 'Description', $result['description'], true, '25');
  581. $inputs .= wf_Selector(self::FORM_EDIT . '[icon_color]', array(
  582. 'blue' => 'blue',
  583. 'orange' => 'orange',
  584. 'darkblue' => 'darkblue',
  585. 'pink' => 'pink',
  586. 'darkgreen' => 'darkgreen',
  587. 'red' => 'red',
  588. 'darkorange' => 'darkorange',
  589. 'violet' => 'violet',
  590. 'green' => 'green',
  591. 'white' => 'white',
  592. 'grey' => 'grey',
  593. 'yellow' => 'yellow',
  594. 'lightblue' => 'lightblue',
  595. 'brown' => 'brown',
  596. 'night' => 'night',
  597. 'black' => 'black'
  598. ), 'Icon color', $result['icon_color'], true, '25');
  599. $inputs .= wf_Selector(self::FORM_EDIT . '[icon_style]', array(
  600. '' => '',
  601. 'Dot' => 'Dot',
  602. 'Stretchy' => 'Stretchy'
  603. ), 'Icon style', $result['icon_style'], true, '25');
  604. $inputs .= wf_Submit('Save', 'ubButton');
  605. // Generate HTML-form:
  606. return wf_Form('', 'POST', $inputs, 'glamour');
  607. }
  608. /**
  609. * Adds marks type to database
  610. *
  611. * @return mixed MySQL-query result
  612. */
  613. public function mark_type_add_form_submit($data) {
  614. $query = "
  615. INSERT INTO `" . self::TABLE_MARKS_TYPES . "` (
  616. `id`,
  617. `type`,
  618. `model`,
  619. `description`,
  620. `icon_color`,
  621. `icon_style`
  622. ) VALUES (
  623. NULL,
  624. '" . $data['type'] . "',
  625. '" . $data['model'] . "',
  626. '" . $data['description'] . "',
  627. '" . $data['icon_color'] . "',
  628. '" . (!empty($data['icon_style']) ? $data['icon_style'] : null ) . "'
  629. );
  630. ";
  631. return nr_query($query);
  632. }
  633. /**
  634. * Updates marks type data in database
  635. *
  636. * @return boolean true
  637. */
  638. public function mark_type_edit_form_submit($id, $data) {
  639. $where = "WHERE `id` = '" . $id . "'";
  640. foreach ($data as $column => $new_value) {
  641. simple_update_field(self::TABLE_MARKS_TYPES, $column, $new_value, $where);
  642. }
  643. return true;
  644. }
  645. /**
  646. * Deletes marks type from database
  647. *
  648. * @param string $id ID of line
  649. * @return mixed MySQL-query result
  650. */
  651. public function mark_type_delete($id) {
  652. $query = "DELETE FROM `" . self::TABLE_MARKS_TYPES . "` WHERE `id` = '" . $id . "'";
  653. return nr_query($query);
  654. }
  655. /* MARKS */
  656. /**
  657. * Returns HTML-table, containing existing marks
  658. *
  659. * @return string HTML-table
  660. */
  661. public function mark_list_show() {
  662. // Query marks:
  663. $query = "SELECT
  664. `" . self::TABLE_MARKS . "`.`id`,
  665. `" . self::TABLE_MARKS_TYPES . "`.`type`,
  666. `" . self::TABLE_MARKS . "`.`number`,
  667. `" . self::TABLE_MARKS . "`.`placement`,
  668. `" . self::TABLE_MARKS . "`.`description`,
  669. `" . self::TABLE_MARKS . "`.`geo`
  670. FROM `" . self::TABLE_MARKS . "`
  671. LEFT JOIN `" . self::TABLE_MARKS_TYPES . "`
  672. ON `" . self::TABLE_MARKS_TYPES . "`.`id` = `" . self::TABLE_MARKS . "`.`type_id`
  673. ";
  674. $result = simple_queryall($query);
  675. // HTML-table header:
  676. $cells = wf_TableCell(__('ID'));
  677. $cells .= wf_TableCell(__('Type'));
  678. $cells .= wf_TableCell(__('Number'));
  679. $cells .= wf_TableCell(__('Placement'));
  680. $cells .= wf_TableCell(__('Description'), 500);
  681. $cells .= wf_TableCell(__('Actions'), 80);
  682. $rows = wf_TableRow($cells, 'row2');
  683. // HTML-table content:
  684. if (!empty($result)) {
  685. foreach ($result as $mark) {
  686. $cells = wf_TableCell($mark['id']);
  687. $cells .= wf_TableCell($mark['type']);
  688. $cells .= wf_TableCell($mark['number']);
  689. $cells .= wf_TableCell($mark['placement']);
  690. $cells .= wf_TableCell($mark['description']);
  691. // Actions:
  692. $actions = wf_Link(self::URL_MARK_DEL . $mark['id'], web_delete_icon());
  693. $actions .= wf_Link(self::URL_MARK_EDIT . $mark['id'], web_edit_icon());
  694. $actions .= wf_Link(self::URL_MARK_DOCS . $mark['id'], web_corporate_icon('Documentation'));
  695. if ($mark['geo'] == '[ ]' || empty($mark['geo'])) {
  696. $actions .= wf_Link(self::URL_MARK_PLACE . $mark['id'], web_add_icon(__('Place on map')));
  697. }
  698. $cells .= wf_TableCell($actions);
  699. $rows .= wf_TableRow($cells, 'row3');
  700. }
  701. } else {
  702. $cells = wf_TableCell(__('There is no marks to show'), null, null, 'colspan="8" align="center"');
  703. $rows .= wf_TableRow($cells, 'row3');
  704. }
  705. // Generate HTML-table:
  706. return wf_TableBody($rows, '100%', '0', 'sortable');
  707. }
  708. /**
  709. * Returns mark add form
  710. *
  711. * @return string Generated HTML-form
  712. */
  713. public function mark_add_form_show() {
  714. // Get marks types:
  715. $types = $this->get_marks_types();
  716. // Fill in the inputs:
  717. $inputs = wf_Selector(self::FORM_ADD . '[type_id]', $types, 'Type', null, true);
  718. $inputs .= wf_TextInput(self::FORM_ADD . '[number]', 'Number', null, true, '25');
  719. $inputs .= wf_TextInput(self::FORM_ADD . '[placement]', 'Placement', null, true, '25');
  720. $inputs .= wf_TextInput(self::FORM_ADD . '[description]', 'Description', null, true, '25');
  721. $inputs .= wf_Submit('Save', 'ubButton');
  722. // Generate HTML-form:
  723. return wf_Form('', 'POST', $inputs, 'glamour');
  724. }
  725. /**
  726. * Returns mark edit form
  727. *
  728. * @return string HTML-form
  729. */
  730. public function mark_edit_form_show($id) {
  731. // Get current data from database:
  732. $query = "SELECT * FROM `" . self::TABLE_MARKS . "` WHERE `id` = '" . $id . "'";
  733. $result = simple_query($query);
  734. // Get closure types:
  735. $types = $this->get_marks_types();
  736. // Fill in the inputs:
  737. $inputs = wf_Selector(self::FORM_EDIT . '[type_id]', $types, 'Type', $result['type_id'], true);
  738. $inputs .= wf_TextInput(self::FORM_EDIT . '[number]', 'Number', $result['number'], true, '25');
  739. $inputs .= wf_TextInput(self::FORM_EDIT . '[placement]', 'Placement', $result['placement'], true, '25');
  740. $inputs .= wf_TextInput(self::FORM_EDIT . '[description]', 'Description', $result['description'], true, '25');
  741. $inputs .= wf_Submit('Edit', 'ubButton');
  742. // Generate HTML-form:
  743. return wf_Form('', 'POST', $inputs, 'glamour');
  744. }
  745. /**
  746. * Adds mark to database
  747. *
  748. * @return mixed MySQL-query result
  749. */
  750. public function mark_add_form_submit($data) {
  751. $query = "
  752. INSERT INTO `" . self::TABLE_MARKS . "` (
  753. `id`,
  754. `type_id`,
  755. `number`,
  756. `placement`,
  757. `description`,
  758. `geo`
  759. ) VALUES (
  760. NULL,
  761. '" . $data['type_id'] . "',
  762. '" . $data['number'] . "',
  763. '" . $data['placement'] . "',
  764. '" . $data['description'] . "',
  765. NULL
  766. );
  767. ";
  768. return nr_query($query);
  769. }
  770. /**
  771. * Updates mark data in database
  772. *
  773. * @return boolean true
  774. */
  775. public function mark_edit_form_submit($id, $data) {
  776. $where = "WHERE `id` = '" . $id . "'";
  777. foreach ($data as $column => $new_value) {
  778. simple_update_field(self::TABLE_MARKS, $column, $new_value, $where);
  779. }
  780. return true;
  781. }
  782. /**
  783. * Deletes mark from database
  784. *
  785. * @param string $id ID of line
  786. * @return mixed MySQL-query result
  787. */
  788. public function mark_delete($id) {
  789. $query = "SELECT `id` FROM `" . self::TABLE_DOCS . "` WHERE `mark_id` = '" . $id . "'";
  790. $result = simple_queryall($query);
  791. if (!empty($result)) {
  792. foreach ($result as $document) {
  793. $this->document_delete($document['id'], false);
  794. }
  795. }
  796. $query = "DELETE FROM `" . self::TABLE_MARKS . "` WHERE `id` = '" . $id . "'";
  797. return nr_query($query);
  798. }
  799. /* LINES */
  800. /**
  801. * Generates HTML-table, containing existing lines
  802. *
  803. * @return string HTML-table
  804. */
  805. public function line_list_show() {
  806. // Query lines:
  807. $query = "SELECT
  808. `" . self::TABLE_LINES . "`.`id`,
  809. `" . self::TABLE_LINES . "`.`point_start`,
  810. `" . self::TABLE_LINES . "`.`point_end`,
  811. `" . self::TABLE_LINES . "`.`fibers_amount`,
  812. `" . self::TABLE_LINES . "`.`length`,
  813. `" . self::TABLE_LINES . "`.`description`,
  814. `employee`.`name` AS `engineer`,
  815. `" . self::TABLE_LINES . "`.`param_color`,
  816. `" . self::TABLE_LINES . "`.`geo`
  817. FROM `" . self::TABLE_LINES . "`
  818. LEFT JOIN `employee`
  819. ON `" . self::TABLE_LINES . "`.`employee_id` = `employee`.id
  820. ";
  821. $result = simple_queryall($query);
  822. // HTML-table header:
  823. $cells = wf_TableCell(__('ID'));
  824. $cells .= wf_TableCell(__('Starting point'));
  825. $cells .= wf_TableCell(__('End point'));
  826. $cells .= wf_TableCell(__('Fibers amount'), 75);
  827. $cells .= wf_TableCell(__('Length'), 100);
  828. $cells .= wf_TableCell(__('Description'), 350);
  829. $cells .= wf_TableCell(__('Engineer'));
  830. $cells .= wf_TableCell(__('Color'), 60);
  831. $cells .= wf_TableCell(__('Actions'), 80);
  832. $rows = wf_TableRow($cells, 'row2');
  833. // HTML-table content:
  834. if (!empty($result)) {
  835. foreach ($result as $line) {
  836. // Color decoration:
  837. $line['param_color'] = '<span style="color: ' . $line['param_color'] . '">' . $line['param_color'] . '</span>';
  838. $cells = wf_TableCell($line['id']);
  839. $cells .= wf_TableCell($line['point_start']);
  840. $cells .= wf_TableCell($line['point_end']);
  841. $cells .= wf_TableCell($line['fibers_amount']);
  842. $cells .= wf_TableCell($line['length']);
  843. $cells .= wf_TableCell($line['description']);
  844. $cells .= wf_TableCell($line['engineer']);
  845. $cells .= wf_TableCell($line['param_color']);
  846. // Actions:
  847. $actions = wf_Link(self::URL_LINE_DEL . $line['id'], web_delete_icon());
  848. $actions .= wf_Link(self::URL_LINE_EDIT . $line['id'], web_edit_icon());
  849. $actions .= wf_Link(self::URL_LINE_DOCS . $line['id'], web_corporate_icon('Documentation'));
  850. if (empty($line['geo']) || $line['geo'] == '[ ]') {
  851. $actions .= wf_Link(self::URL_LINE_PLACE . $line['id'], web_add_icon(__('Place on map')));
  852. }
  853. $cells .= wf_TableCell($actions);
  854. $rows .= wf_TableRow($cells, 'row3');
  855. }
  856. } else {
  857. $cells = wf_TableCell(__('There is no lines to show'), null, null, 'colspan="9" align="center"');
  858. $rows .= wf_TableRow($cells, 'row3');
  859. }
  860. // Generate HTML-table:
  861. return wf_TableBody($rows, '100%', '0');
  862. }
  863. /**
  864. * Returns line add form
  865. *
  866. * @return string Generated HTML-form
  867. */
  868. public function line_add_form_show() {
  869. // Get employee:
  870. $employee = $this->get_employee();
  871. // Fill in the inputs:
  872. $inputs = wf_TextInput(self::FORM_ADD . '[point_start]', 'Starting point', null, true, '25');
  873. $inputs .= wf_TextInput(self::FORM_ADD . '[point_end]', 'End point', null, true, '25');
  874. $inputs .= wf_TextInput(self::FORM_ADD . '[fibers_amount]', 'Fibers amount', null, true, '25');
  875. $inputs .= wf_TextInput(self::FORM_ADD . '[length]', 'Length', null, true, '25');
  876. $inputs .= wf_TextInput(self::FORM_ADD . '[description]', 'Description', null, true, '25');
  877. $inputs .= wf_Selector(self::FORM_ADD . '[employee_id]', $employee, 'Engineer', null, true);
  878. $inputs .= wf_ColPicker(self::FORM_ADD . '[param_color]', 'Color', '#f57601', true, '25');
  879. $inputs .= wf_TextInput(self::FORM_ADD . '[param_width]', 'Line width', 2, true, '25');
  880. $inputs .= wf_Submit('Save', 'ubButton');
  881. // Generate HTML-form:
  882. return wf_Form('', 'POST', $inputs, 'glamour');
  883. }
  884. /**
  885. * Returns line edit form
  886. *
  887. * @return string HTML-form
  888. */
  889. public function line_edit_form_show($id) {
  890. // Get employee:
  891. $employee = $this->get_employee();
  892. // Get current data from database:
  893. $query = "SELECT * FROM `" . self::TABLE_LINES . "` WHERE `id` = '" . $id . "'";
  894. $result = simple_query($query);
  895. // Fill in the inputs:
  896. $inputs = wf_TextInput(self::FORM_EDIT . '[point_start]', 'Starting point', $result['point_start'], true, '25');
  897. $inputs .= wf_TextInput(self::FORM_EDIT . '[point_end]', 'End point', $result['point_end'], true, '25');
  898. $inputs .= wf_TextInput(self::FORM_EDIT . '[fibers_amount]', 'Fibers amount', $result['fibers_amount'], true, '25');
  899. $inputs .= wf_TextInput(self::FORM_EDIT . '[length]', 'Length', $result['length'], true, '25');
  900. $inputs .= wf_TextInput(self::FORM_EDIT . '[description]', 'Description', $result['description'], true, '25');
  901. $inputs .= wf_Selector(self::FORM_EDIT . '[employee_id]', $employee, 'Engineer', $result['employee_id'], true);
  902. $inputs .= wf_ColPicker(self::FORM_EDIT . '[param_color]', 'Color', $result['param_color'], true, '25');
  903. $inputs .= wf_TextInput(self::FORM_EDIT . '[param_width]', 'Line width', $result['param_width'], true, '25');
  904. $inputs .= wf_Submit('Save', 'ubButton');
  905. // Generate HTML-form:
  906. return wf_Form('', 'POST', $inputs, 'glamour');
  907. }
  908. /**
  909. * Adds line to database
  910. *
  911. * @return mixed Returns MySQL-query result
  912. */
  913. public function line_add_form_submit($data) {
  914. $query = "
  915. INSERT INTO `" . self::TABLE_LINES . "` (
  916. `id`,
  917. `point_start`,
  918. `point_end`,
  919. `fibers_amount`,
  920. `length`,
  921. `description`,
  922. `employee_id`,
  923. `param_color`,
  924. `param_width`,
  925. `geo`
  926. ) VALUES (
  927. NULL,
  928. '" . $data['point_start'] . "',
  929. '" . $data['point_end'] . "',
  930. '" . $data['fibers_amount'] . "',
  931. '" . $data['length'] . "',
  932. '" . $data['description'] . "',
  933. '" . $data['employee_id'] . "',
  934. '" . $data['param_color'] . "',
  935. '" . $data['param_width'] . "',
  936. NULL
  937. );
  938. ";
  939. return nr_query($query);
  940. }
  941. /**
  942. * Updates line data in database
  943. *
  944. * @return boolean true
  945. */
  946. public function line_edit_form_submit($id, $data) {
  947. $where = "WHERE `id` = '" . $id . "'";
  948. foreach ($data as $column => $new_value) {
  949. simple_update_field(self::TABLE_LINES, $column, $new_value, $where);
  950. }
  951. return true;
  952. }
  953. /**
  954. * Deletes line from database
  955. *
  956. * @param string $id ID of line
  957. * @return mixed MySQL-query result
  958. */
  959. public function line_delete($id) {
  960. $query = "SELECT `id` FROM `" . self::TABLE_DOCS . "` WHERE `line_id` = '" . $id . "'";
  961. $result = simple_queryall($query);
  962. if (!empty($result)) {
  963. foreach ($result as $document) {
  964. $this->document_delete($document['id'], false);
  965. }
  966. }
  967. $query = "DELETE FROM `" . self::TABLE_LINES . "` WHERE `id` = '" . $id . "'";
  968. return nr_query($query);
  969. }
  970. /* DOCUMENTS */
  971. public function documents_list_show($item, $item_id) {
  972. // Get documents list using the elements' id:
  973. $query = "SELECT * FROM `" . self::TABLE_DOCS . "` WHERE `" . $item . "_id` = '" . $item_id . "'";
  974. $result = simple_queryall($query);
  975. $cells = wf_TableCell(__('ID'));
  976. $cells .= wf_TableCell(__('Title'));
  977. $cells .= wf_TableCell(__('Date'));
  978. $cells .= wf_TableCell(__('Filename'));
  979. $cells .= wf_TableCell(__('Actions'));
  980. $rows = wf_TableRow($cells, 'row2');
  981. if (!empty($result)) {
  982. foreach ($result as $document) {
  983. $filename = basename($document['path']);
  984. $cells = wf_TableCell($document['id']);
  985. $cells .= wf_TableCell($document['title']);
  986. $cells .= wf_TableCell($document['date']);
  987. $cells .= wf_TableCell($filename);
  988. $actions = wf_Link(self::URL_DOC_DOWNLOAD . $document['id'], wf_img('skins/icon_download.png', __('Download')));
  989. $actions .= wf_Link(self::URL_DOC_DELETE . $document['id'], web_delete_icon());
  990. $cells .= wf_TableCell($actions);
  991. $rows .= wf_TableRow($cells, 'row3');
  992. }
  993. } else {
  994. $cells = wf_TableCell(__('There is no documents to show'), null, null, 'colspan="5" align="center"');
  995. $rows .= wf_TableRow($cells, 'row3');
  996. }
  997. return wf_TableBody($rows, '100%', '0');
  998. }
  999. public function document_add_form_show($item, $item_id) {
  1000. $inputs = wf_HiddenInput(self::FORM_ADD . '[' . $item . '_id]', $item_id);
  1001. $inputs .= wf_TextInput(self::FORM_ADD . '[title]', __('Title'), null, true, '20');
  1002. $inputs .= __('Select document from HDD') . wf_tag('br');
  1003. $inputs .= wf_tag('input', false, '', 'id="fileselector" type="file" name="' . self::FORM_ADD . '[file]"') . wf_tag('br');
  1004. $inputs .= wf_Submit('Upload');
  1005. return bs_UploadFormBody('', 'POST', $inputs, 'glamour');
  1006. }
  1007. public function document_add_form_submit($item, $item_id, $data) {
  1008. $return = false;
  1009. if (!empty($data['title'])) {
  1010. $file_name = uniqid();
  1011. $file_extention = pathinfo($_FILES[self::FORM_ADD]['name']['file'], PATHINFO_EXTENSION);
  1012. $upload_path = DATA_PATH . 'documents/vols/' . $file_name . '.' . $file_extention;
  1013. if (move_uploaded_file($_FILES[self::FORM_ADD]['tmp_name']['file'], $upload_path)) {
  1014. $return = true;
  1015. $query = "
  1016. INSERT INTO `" . self::TABLE_DOCS . "` (
  1017. `id`,
  1018. `title`,
  1019. `date`,
  1020. `" . $item . "_id`,
  1021. `path`
  1022. ) VALUES (
  1023. NULL,
  1024. '" . $data['title'] . "',
  1025. NOW(),
  1026. '" . $item_id . "',
  1027. '" . $upload_path . "'
  1028. )
  1029. ";
  1030. nr_query($query);
  1031. } else
  1032. show_window(__('Error'), __('You should add any file'));
  1033. } else
  1034. show_window(__('Error'), __('No display title for document'));
  1035. return $return;
  1036. }
  1037. /**
  1038. * Sends document on the server to the browser for downloading
  1039. *
  1040. * @param type $document_id ID of the downloading document
  1041. */
  1042. public function document_download($id) {
  1043. // Get info about downloading file:
  1044. $query = "SELECT * FROM `" . self::TABLE_DOCS . "` WHERE `id` = '" . $id . "'";
  1045. $result = simple_query($query);
  1046. // Send document to browser:
  1047. $document = file_get_contents($result['path']);
  1048. log_register("DOWNLOAD FILE `" . $result['path'] . "`");
  1049. header('Content-Type: application/octet-stream');
  1050. header("Content-Transfer-Encoding: Binary");
  1051. header("Content-disposition: attachment; filename=\"" . $result['title'] . '.' . pathinfo($result['path'], PATHINFO_EXTENSION) . "\"");
  1052. die($document);
  1053. }
  1054. /**
  1055. * Deletes document from database and filesystem and redirects back to
  1056. * documents list of the node
  1057. *
  1058. * @param type $document_id ID of the deleting document
  1059. * @return type
  1060. */
  1061. public function document_delete($id, $redirect = true) {
  1062. // Get info about deleting file:
  1063. $query = "SELECT * FROM `" . self::TABLE_DOCS . "` WHERE `id` = '" . $id . "'";
  1064. $result = simple_query($query);
  1065. // Delete from database if deleted from filesystem:
  1066. if (unlink($result['path'])) {
  1067. $query = "DELETE FROM `" . self::TABLE_DOCS . "` WHERE `id` = '" . $id . "'";
  1068. nr_query($query);
  1069. if ($redirect) {
  1070. $item = empty($result['mark_id']) ? 'line' : 'mark';
  1071. $item_id = empty($result['mark_id']) ? $result['line_id'] : $result['mark_id'];
  1072. rcms_redirect('?module=vols&item=' . $item . '&action=documents&id=' . $item_id);
  1073. }
  1074. }
  1075. }
  1076. }
  1077. /**
  1078. * Controller:
  1079. */
  1080. $alter = $ubillingConfig->getAlter();
  1081. if (!empty($alter['VOLS_ENABLED'])) {
  1082. $greed = new Avarice();
  1083. $runtime = $greed->runtime('VOLS');
  1084. if (!empty($runtime)) {
  1085. $obj = new VOLS();
  1086. if (wf_CheckGet(array('item', 'action'))) {
  1087. $item = vf($_GET['item'], 4);
  1088. $action = vf($_GET['action'], 4);
  1089. switch ($item) {
  1090. case 'map':
  1091. switch ($action) {
  1092. case 'show':
  1093. if (isset($runtime['METHOD']['RNDR']) and method_exists($obj, $runtime['METHOD']['RNDR']))
  1094. $runtimeA = $runtime['METHOD']['RNDR'];
  1095. show_window(__('Map of VOLS'), $obj->$runtimeA());
  1096. break;
  1097. case 'edit':
  1098. if (isset($runtime['METHOD']['RNDR']) and method_exists($obj, $runtime['METHOD']['RNDR']))
  1099. $runtimeB = $runtime['METHOD']['RNDR'];
  1100. show_window(__('Map of VOLS'), $obj->$runtimeB(true));
  1101. break;
  1102. default:
  1103. // Переадресация на главную стр. модуля при попытке доступа
  1104. // к несуществующему обработчику $_GET['action']:
  1105. rcms_redirect($obj::URL_HOME);
  1106. break;
  1107. }
  1108. break;
  1109. case 'mark_type':
  1110. switch ($action) {
  1111. case 'list':
  1112. // Show window:
  1113. $title = __('Types of marks') . ' ';
  1114. $title .= wf_Link($obj::URL_MAP_SHOW, wf_img('skins/vols_nav/map.png', __('Map of VOLS'))) . ' ';
  1115. $title .= wf_Link($obj::URL_MARK_TYPE_ADD, wf_img('skins/vols_nav/add.png', __('Create')));
  1116. if (isset($runtime['METHOD']['MRKTPLST']) and method_exists($obj, $runtime['METHOD']['MRKTPLST']))
  1117. $runtimeC = $runtime['METHOD']['MRKTPLST'];
  1118. show_window($title, $obj->$runtimeC());
  1119. break;
  1120. case 'add':
  1121. // Form submit handle:
  1122. if (wf_CheckPost(array($obj::FORM_ADD))) {
  1123. $data = $_POST[$obj::FORM_ADD];
  1124. if ($obj->mark_type_add_form_submit($data)) {
  1125. rcms_redirect($obj::URL_MARK_TYPES_LIST);
  1126. }
  1127. }
  1128. // Show window:
  1129. $title = __('Adding of marks type') . ' ';
  1130. $title .= wf_Link($obj::URL_MAP_SHOW, wf_img('skins/vols_nav/map.png', __('Map of VOLS'))) . ' ';
  1131. $title .= wf_Link($obj::URL_MARK_TYPES_LIST, wf_img('skins/vols_nav/arrow-left.png', __('Back'))) . ' ';
  1132. if (isset($runtime['METHOD']['MRKTPD']) and method_exists($obj, $runtime['METHOD']['MRKTPD']))
  1133. $runtimeD = $runtime['METHOD']['MRKTPD'];
  1134. show_window($title, $obj->$runtimeD());
  1135. break;
  1136. case 'edit':
  1137. if (wf_CheckGet(array('id'))) {
  1138. $id = vf($_GET['id'], 3);
  1139. // Form submit handle:
  1140. if (wf_CheckPost(array($obj::FORM_EDIT))) {
  1141. $data = $_POST[$obj::FORM_EDIT];
  1142. if ($obj->mark_type_edit_form_submit($id, $data)) {
  1143. rcms_redirect($obj::URL_MARK_TYPES_LIST);
  1144. }
  1145. }
  1146. // Show window:
  1147. $title = __('Editing of marks type') . ' ';
  1148. $title .= wf_Link($obj::URL_MAP_SHOW, wf_img('skins/vols_nav/map.png', __('Map of VOLS'))) . ' ';
  1149. $title .= wf_Link($obj::URL_MARK_TYPES_LIST, wf_img('skins/vols_nav/arrow-left.png', __('Back'))) . ' ';
  1150. if (isset($runtime['METHOD']['MRKTPDT']) and method_exists($obj, $runtime['METHOD']['MRKTPDT']))
  1151. $runtimeE = $runtime['METHOD']['MRKTPDT'];
  1152. show_window($title, $obj->$runtimeE($id));
  1153. } else
  1154. rcms_redirect($obj::URL_MARK_TYPES_LIST);
  1155. break;
  1156. case 'delete':
  1157. if (wf_CheckGet(array('id'))) {
  1158. $id = vf($_GET['id'], 3);
  1159. if (isset($runtime['METHOD']['MRKTPDLT']) and method_exists($obj, $runtime['METHOD']['MRKTPDLT'])) {
  1160. $runtimeF = $runtime['METHOD']['MRKTPDLT'];
  1161. if ($obj->$runtimeF($id)) {
  1162. rcms_redirect($obj::URL_MARK_TYPES_LIST);
  1163. }
  1164. }
  1165. } else
  1166. rcms_redirect($obj::URL_MARK_TYPES_LIST);
  1167. break;
  1168. }
  1169. break;
  1170. case 'mark':
  1171. switch ($action) {
  1172. case 'list':
  1173. // Show window:
  1174. $title = __('VOLS marks') . ' ';
  1175. $title .= wf_Link($obj::URL_MAP_SHOW, wf_img('skins/vols_nav/map.png', __('Map of VOLS'))) . ' ';
  1176. $title .= wf_Link($obj::URL_MARK_ADD, wf_img('skins/vols_nav/add.png', __('Add mark'))) . ' ';
  1177. if (isset($runtime['METHOD']['MRKLST']) and method_exists($obj, $runtime['METHOD']['MRKLST']))
  1178. $runtimeH = $runtime['METHOD']['MRKLST'];
  1179. show_window($title, $obj->$runtimeH());
  1180. break;
  1181. case 'add':
  1182. // Form submit handle:
  1183. if (wf_CheckPost(array($obj::FORM_ADD))) {
  1184. $data = $_POST[$obj::FORM_ADD];
  1185. if ($obj->mark_add_form_submit($data)) {
  1186. rcms_redirect($obj::URL_MARKS_LIST);
  1187. }
  1188. }
  1189. // Show window:
  1190. $title = __('Adding of mark') . ' ';
  1191. $title .= wf_Link($obj::URL_MAP_SHOW, wf_img('skins/vols_nav/map.png', __('Map of VOLS'))) . ' ';
  1192. $title .= wf_Link($obj::URL_MARKS_LIST, wf_img('skins/vols_nav/arrow-left.png', __('Back'))) . ' ';
  1193. if (isset($runtime['METHOD']['MRKD']) and method_exists($obj, $runtime['METHOD']['MRKD']))
  1194. $runtimeI = $runtime['METHOD']['MRKD'];
  1195. show_window($title, $obj->$runtimeI());
  1196. break;
  1197. case 'place':
  1198. if (wf_CheckGet(array('id'))) {
  1199. $id = vf($_GET['id'], 3);
  1200. $obj->place_placemark($id);
  1201. if (isset($runtime['METHOD']['MRKPLC']) and method_exists($obj, $runtime['METHOD']['MRKPLC']))
  1202. $runtimeJ = $runtime['METHOD']['MRKPLC'];
  1203. show_window(__('Map of VOLS'), $obj->$runtimeJ());
  1204. } else
  1205. rcms_redirect($obj::URL_LINES_LIST);
  1206. break;
  1207. case 'edit':
  1208. if (wf_CheckGet(array('id'))) {
  1209. $id = vf($_GET['id'], 3);
  1210. // Form submit handle:
  1211. if (wf_CheckPost(array($obj::FORM_EDIT))) {
  1212. $data = $_POST[$obj::FORM_EDIT];
  1213. // The ajax check:
  1214. if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])) {
  1215. die($obj->mark_edit_form_submit($id, $data));
  1216. } else {
  1217. $obj->mark_edit_form_submit($id, $data);
  1218. rcms_redirect($obj::URL_MARKS_LIST);
  1219. }
  1220. }
  1221. // Show window:
  1222. $title = __('Editing of mark') . ' ';
  1223. $title .= wf_Link($obj::URL_MAP_SHOW, wf_img('skins/vols_nav/map.png', __('Map of VOLS'))) . ' ';
  1224. $title .= wf_Link($obj::URL_MARKS_LIST, wf_img('skins/vols_nav/arrow-left.png', __('Back'))) . ' ';
  1225. if (isset($runtime['METHOD']['MRKDT']) and method_exists($obj, $runtime['METHOD']['MRKDT']))
  1226. $runtimeK = $runtime['METHOD']['MRKDT'];
  1227. show_window($title, $obj->$runtimeK($id));
  1228. } else
  1229. rcms_redirect($obj::URL_MARKS_LIST);
  1230. break;
  1231. case 'delete':
  1232. if (wf_CheckGet(array('id'))) {
  1233. $id = vf($_GET['id'], 3);
  1234. if (isset($runtime['METHOD']['MRKDLT']) and method_exists($obj, $runtime['METHOD']['MRKDLT'])) {
  1235. $runtimeL = $runtime['METHOD']['MRKDLT'];
  1236. if ($obj->$runtimeL($id)) {
  1237. rcms_redirect($obj::URL_MARKS_LIST);
  1238. }
  1239. }
  1240. } else
  1241. rcms_redirect($obj::URL_MARKS_LIST);
  1242. break;
  1243. case 'documents':
  1244. if (wf_CheckGet(array('id'))) {
  1245. $id = vf($_GET['id'], 3);
  1246. // Form submit handle:
  1247. if (wf_CheckPost(array($obj::FORM_ADD))) {
  1248. $data = $_POST[$obj::FORM_ADD];
  1249. $obj->document_add_form_submit($item, $id, $data);
  1250. }
  1251. // Title + navigation buttons:
  1252. $title = __('Documentation of VOLS') . ' ';
  1253. $title .= wf_Link($obj::URL_MAP_SHOW, wf_img('skins/vols_nav/map.png', __('Map of VOLS'))) . ' ';
  1254. $title .= wf_Link($obj::URL_MARKS_LIST, wf_img('skins/vols_nav/arrow-left.png', __('Back'))) . ' ';
  1255. // Show window:
  1256. if (isset($runtime['METHOD']['MRKDCMNTSLST']) and method_exists($obj, $runtime['METHOD']['MRKDCMNTSLST']))
  1257. $runtimeM = $runtime['METHOD']['MRKDCMNTSLST'];
  1258. show_window($title, $obj->$runtimeM($item, $id));
  1259. if (isset($runtime['METHOD']['MRKDCMNTSD']) and method_exists($obj, $runtime['METHOD']['MRKDCMNTSD']))
  1260. $runtimeN = $runtime['METHOD']['MRKDCMNTSD'];
  1261. show_window(__('Adding of document'), $obj->$runtimeN($item, $id));
  1262. } else
  1263. rcms_redirect($obj::URL_MARKS_LIST);
  1264. break;
  1265. }
  1266. break;
  1267. case 'line':
  1268. switch ($action) {
  1269. case 'list':
  1270. // Title + navigation buttons:
  1271. $title = __('VOLS lines') . ' ';
  1272. $title .= wf_Link($obj::URL_MAP_SHOW, wf_img('skins/vols_nav/map.png', __('Map of VOLS'))) . ' ';
  1273. $title .= wf_Link($obj::URL_LINE_ADD, wf_img('skins/vols_nav/add.png', __('Create')));
  1274. // Show window:
  1275. if (isset($runtime['METHOD']['LNLST']) and method_exists($obj, $runtime['METHOD']['LNLST']))
  1276. $runtimeO = $runtime['METHOD']['LNLST'];
  1277. show_window($title, $obj->$runtimeO());
  1278. break;
  1279. case 'add':
  1280. // Form submit handle:
  1281. if (wf_CheckPost(array($obj::FORM_ADD))) {
  1282. $data = $_POST[$obj::FORM_ADD];
  1283. if ($obj->line_add_form_submit($data)) {
  1284. rcms_redirect($obj::URL_LINES_LIST);
  1285. }
  1286. }
  1287. // Show window:
  1288. $title = __('Adding of line') . ' ';
  1289. $title .= wf_Link($obj::URL_MAP_SHOW, wf_img('skins/vols_nav/map.png', __('Map of VOLS'))) . ' ';
  1290. $title .= wf_Link($obj::URL_LINES_LIST, wf_img('skins/vols_nav/arrow-left.png', __('Back'))) . ' ';
  1291. if (isset($runtime['METHOD']['LND']) and method_exists($obj, $runtime['METHOD']['LND']))
  1292. $runtimeP = $runtime['METHOD']['LND'];
  1293. show_window($title, $obj->$runtimeP());
  1294. break;
  1295. case 'place':
  1296. if (wf_CheckGet(array('id'))) {
  1297. $id = vf($_GET['id'], 3);
  1298. $obj->place_polyline($id);
  1299. if (isset($runtime['METHOD']['LNPLC']) and method_exists($obj, $runtime['METHOD']['LNPLC']))
  1300. $runtimeS = $runtime['METHOD']['LNPLC'];
  1301. show_window(__('Map of VOLS'), $obj->$runtimeS());
  1302. } else
  1303. rcms_redirect($obj::URL_LINES_LIST);
  1304. break;
  1305. case 'edit':
  1306. if (wf_CheckGet(array('id'))) {
  1307. $id = vf($_GET['id'], 3);
  1308. // Form submit handle:
  1309. if (wf_CheckPost(array($obj::FORM_EDIT))) {
  1310. $data = $_POST[$obj::FORM_EDIT];
  1311. // The ajax check:
  1312. if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])) {
  1313. die($obj->line_edit_form_submit($id, $data));
  1314. } else {
  1315. $obj->line_edit_form_submit($id, $data);
  1316. rcms_redirect($obj::URL_LINES_LIST);
  1317. }
  1318. }
  1319. // Show window:
  1320. $title = __('Editing of line') . ' ';
  1321. $title .= wf_Link($obj::URL_MAP_SHOW, wf_img('skins/vols_nav/map.png', __('Map of VOLS'))) . ' ';
  1322. $title .= wf_Link($obj::URL_LINES_LIST, wf_img('skins/vols_nav/arrow-left.png', __('Back'))) . ' ';
  1323. if (isset($runtime['METHOD']['LNDT']) and method_exists($obj, $runtime['METHOD']['LNDT']))
  1324. $runtimeQ = $runtime['METHOD']['LNDT'];
  1325. show_window($title, $obj->$runtimeQ($id));
  1326. } else
  1327. rcms_redirect($obj::URL_LINES_LIST);
  1328. break;
  1329. case 'delete':
  1330. if (wf_CheckGet(array('id'))) {
  1331. $id = vf($_GET['id'], 3);
  1332. if (isset($runtime['METHOD']['LNDLT']) and method_exists($obj, $runtime['METHOD']['LNDLT'])) {
  1333. $runtimeR = $runtime['METHOD']['LNDLT'];
  1334. if ($obj->$runtimeR($id)) {
  1335. rcms_redirect($obj::URL_LINES_LIST);
  1336. }
  1337. }
  1338. } else
  1339. rcms_redirect($obj::URL_LINES_LIST);
  1340. break;
  1341. case 'documents':
  1342. if (wf_CheckGet(array('id'))) {
  1343. $id = vf($_GET['id'], 3);
  1344. // Form submit handle:
  1345. if (wf_CheckPost(array($obj::FORM_ADD))) {
  1346. $data = $_POST[$obj::FORM_ADD];
  1347. $obj->document_add_form_submit($item, $id, $data);
  1348. }
  1349. // Title + navigation buttons:
  1350. $title = __('Documentation of VOLS') . ' ';
  1351. $title .= wf_Link($obj::URL_MAP_SHOW, wf_img('skins/vols_nav/map.png', __('Map of VOLS'))) . ' ';
  1352. $title .= wf_Link($obj::URL_LINES_LIST, wf_img('skins/vols_nav/arrow-left.png', __('Back'))) . ' ';
  1353. // Show window:
  1354. if (isset($runtime['METHOD']['LNDCMNTSLST']) and method_exists($obj, $runtime['METHOD']['LNDCMNTSLST']))
  1355. $runtimeT = $runtime['METHOD']['LNDCMNTSLST'];
  1356. show_window($title, $obj->$runtimeT($item, $id));
  1357. if (isset($runtime['METHOD']['LNDCMNTSD']) and method_exists($obj, $runtime['METHOD']['LNDCMNTSD']))
  1358. $runtimeU = $runtime['METHOD']['LNDCMNTSD'];
  1359. show_window(__('Adding of document'), $obj->$runtimeU($item, $id));
  1360. } else
  1361. rcms_redirect($obj::URL_LINES_LIST);
  1362. break;
  1363. default:
  1364. // Переадресация на главную стр. модуля при попытке доступа
  1365. // к несуществующему обработчику $_GET['action']:
  1366. rcms_redirect($obj::URL_HOME);
  1367. break;
  1368. }
  1369. break;
  1370. case 'document':
  1371. switch ($action) {
  1372. case 'download':
  1373. if (wf_CheckGet(array('id'))) {
  1374. $id = vf($_GET['id'], 3);
  1375. if (isset($runtime['METHOD']['DCMNTSDWNLD']) and method_exists($obj, $runtime['METHOD']['DCMNTSDWNLD']))
  1376. $runtimeV = $runtime['METHOD']['DCMNTSDWNLD'];
  1377. $obj->$runtimeV($id);
  1378. } else
  1379. rcms_redirect($obj::URL_HOME);
  1380. break;
  1381. case 'delete':
  1382. if (wf_CheckGet(array('id'))) {
  1383. $id = vf($_GET['id'], 3);
  1384. if (isset($runtime['METHOD']['DCMNTSDLT']) and method_exists($obj, $runtime['METHOD']['DCMNTSDLT']))
  1385. $runtimeW = $runtime['METHOD']['DCMNTSDLT'];
  1386. $obj->$runtimeW($id);
  1387. } else
  1388. rcms_redirect($obj::URL_HOME);
  1389. break;
  1390. default:
  1391. // Переадресация на главную стр. модуля при попытке доступа
  1392. // к несуществующему обработчику $_GET['action']:
  1393. rcms_redirect($obj::URL_HOME);
  1394. break;
  1395. }
  1396. break;
  1397. default:
  1398. // Переадресация на главную стр. модуля при попытке доступа
  1399. // к несуществующему обработчику $_GET['item']:
  1400. rcms_redirect($obj::URL_HOME);
  1401. break;
  1402. }
  1403. } else {
  1404. // Переадресация на главную стр. модуля если не получены все
  1405. // необходисые параметры в $_GET[];
  1406. rcms_redirect($obj::URL_HOME);
  1407. }
  1408. zb_BillingStats(true);
  1409. } else {
  1410. show_window(__('Error'), __('No license key available'));
  1411. }
  1412. } else {
  1413. show_error(__('This module is disabled'));
  1414. }
  1415. } else {
  1416. show_error(__('Access denied'));
  1417. }