api.lightastral.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  1. <?php
  2. /**
  3. * Return web form element id
  4. *
  5. * @return string
  6. */
  7. function la_InputId() {
  8. // I know it looks really funny.
  9. // You can also get a truly random values by throwing dice ;)
  10. $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
  11. $result = "";
  12. for ($p = 0; $p < 8; $p++) {
  13. $result .= $characters[mt_rand(0, (strlen($characters) - 1))];
  14. }
  15. return ($result);
  16. }
  17. /**
  18. * Return web form body
  19. *
  20. * @param string $action action URL
  21. * @param string $method method: POST or GET
  22. * @param string $inputs inputs string to include
  23. * @param string $class class for form
  24. * @param string $legend form legend
  25. * @param bool $cleanStyle clean css style
  26. * @param string $options some inline form options
  27. *
  28. * @return string
  29. */
  30. function la_Form($action, $method, $inputs, $class = '', $legend = '', $cleanStyle = true, $options = '') {
  31. if ($class != '') {
  32. $form_class = ' class="' . $class . '" ';
  33. } else {
  34. $form_class = '';
  35. }
  36. if ($legend != '') {
  37. $form_legend = '<legend>' . __($legend) . '</legend> <br>';
  38. } else {
  39. $form_legend = '';
  40. }
  41. if ($cleanStyle) {
  42. $cleanDiv = '<div style="clear:both;"></div>';
  43. } else {
  44. $cleanDiv = '';
  45. }
  46. $form = '
  47. <form action="' . $action . '" method="' . $method . '" ' . $form_class . ' ' . $options . '>
  48. ' . $form_legend . '
  49. ' . $inputs . '
  50. </form>
  51. ' . $cleanDiv . '
  52. ';
  53. return ($form);
  54. }
  55. /**
  56. * Return text input Web From element
  57. *
  58. * @param string $name name of element
  59. * @param string $label text label for input
  60. * @param string $value current value
  61. * @param bool $br append new line
  62. * @param string $size input size
  63. * @param string $pattern input check pattern. Avaible: geo, mobile, finance, ip, net-cidr, digits, email, alpha, alphanumeric,mac
  64. * @param string $class class of the element
  65. * @param string $ctrlID id of the element
  66. * @param string $options
  67. *
  68. * @return string
  69. *
  70. */
  71. function la_TextInput($name, $label = '', $value = '', $br = false, $size = '', $pattern = '', $class = '', $ctrlID = '', $options = '') {
  72. $inputid = ( empty($ctrlID) ) ? la_InputId() : $ctrlID;
  73. $opts = ( empty($options) ) ? '' : $options;
  74. //set size
  75. if ($size != '') {
  76. $input_size = 'size="' . $size . '"';
  77. } else {
  78. $input_size = '';
  79. }
  80. if ($br) {
  81. $newline = '<br>';
  82. } else {
  83. $newline = '';
  84. }
  85. // We will verify that we correctly enter data by input type
  86. $pattern = ($pattern == 'geo') ? 'pattern="-?\d{1,2}(\.\d+)\s?,\s?-?\d{1,3}(\.\d+)" placeholder="0.00000,0.00000" title="' . __('The format of geographic data can be') . ': 40.7143528,-74.0059731 ; 41.40338, 2.17403 ; -14.235004 , 51.92528"' : $pattern;
  87. $pattern = ($pattern == 'mobile') ? 'pattern="\+?(\d{1,3})?\d{2,3}\d{7}" placeholder="(+)(38)0500000000" title="' . __('The mobile number format can be') . ': +38026121104, 0506430501, 375295431122"' : $pattern;
  88. $pattern = ($pattern == 'finance') ? 'pattern="\d+(\.\d+)?" placeholder="0(.00)" title="' . __('The financial input format can be') . ': 1 ; 4.01 ; 2 ; 0.001"' : $pattern;
  89. // For this pattern IP adress also can be 0.0.0.0
  90. $pattern = ($pattern == 'ip') ? 'pattern="^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$" placeholder="0.0.0.0" title="' . __('The IP address format can be') . ': 192.1.1.1"' : $pattern;
  91. // For this pattern exclude cidr /31
  92. $pattern = ($pattern == 'net-cidr') ? 'pattern="^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\/([0-9]|[1-2][0-9]|30|32)$" placeholder="0.0.0.0/0" title="' . __('The format of IP address with mask can be') . ': 192.1.1.1/32 ' . __('and the mask can not be /31') . '"' : $pattern;
  93. $pattern = ($pattern == 'digits') ? 'pattern="^\d+$" placeholder="0" title="' . __('This field can only contain digits') . '"' : $pattern;
  94. $pattern = ($pattern == 'email') ? 'pattern="^([\w\._-]+)@([\w\._-]+)\.([a-z]{2,6}\.?)$" placeholder="bobrik@bobrik.com" title="' . __('This field can only contain email address') . '"' : $pattern;
  95. $pattern = ($pattern == 'alpha') ? 'pattern="[a-zA-Z]+" placeholder="aZ" title="' . __('This field can only contain Latin letters') . '"' : $pattern;
  96. $pattern = ($pattern == 'alphanumeric') ? 'pattern="[a-zA-Z0-9]+" placeholder="aZ09" title="' . __('This field can only contain Latin letters and numbers') . '"' : $pattern;
  97. $pattern = ($pattern == 'mac') ? 'pattern="^[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}$|^[a-fA-F0-9]{2}-[a-fA-F0-9]{2}-[a-fA-F0-9]{2}-[a-fA-F0-9]{2}-[a-fA-F0-9]{2}-[a-fA-F0-9]{2}$" placeholder="00:02:02:34:72:a5" title="' . __('This MAC have wrong format') . '"' : $pattern;
  98. $result = '<input type="text" name="' . $name . '" value="' . $value . '" ' . $input_size . ' id="' . $inputid . '" class="' . $class . '" ' . $opts . ' ' . $pattern . '>' . "\n";
  99. if ($label != '') {
  100. $result .= ' <label for="' . $inputid . '">' . __($label) . '</label>' . "\n";
  101. }
  102. $result .= $newline . "\n";
  103. return ($result);
  104. }
  105. /**
  106. * Return password input Web From element
  107. *
  108. * @param string $name name of element
  109. * @param string $label text label for input
  110. * @param string $value current value
  111. * @param bool $br append new line
  112. * @param string $size input size
  113. *
  114. * @return string
  115. */
  116. function la_PasswordInput($name, $label = '', $value = '', $br = false, $size = '') {
  117. $inputid = la_InputId();
  118. //set size
  119. if ($size != '') {
  120. $input_size = 'size="' . $size . '"';
  121. } else {
  122. $input_size = '';
  123. }
  124. if ($br) {
  125. $newline = '<br>';
  126. } else {
  127. $newline = '';
  128. }
  129. $result = '<input type="password" name="' . $name . '" value="' . $value . '" ' . $input_size . ' id="' . $inputid . '">' . "\n";
  130. if ($label != '') {
  131. $result .= ' <label for="' . $inputid . '">' . __($label) . '</label>' . "\n";
  132. }
  133. $result .= $newline . "\n";
  134. return ($result);
  135. }
  136. /**
  137. * Return link form element
  138. *
  139. * @param string $url needed URL
  140. * @param string $title text title of URL
  141. * @param bool $br append new line - bool
  142. * @param string $class class for link
  143. * @param string $options for link
  144. *
  145. * @return string
  146. */
  147. function la_Link($url, $title, $br = false, $class = '', $options = '') {
  148. if ($class != '') {
  149. $link_class = 'class="' . $class . '"';
  150. } else {
  151. $link_class = '';
  152. }
  153. if ($br) {
  154. $newline = '<br>';
  155. } else {
  156. $newline = '';
  157. }
  158. $opts = ( empty($options) ) ? '' : ' ' . $options;
  159. $result = '<a href="' . $url . '" ' . $link_class . $opts . '>' . __($title) . '</a>' . "\n";
  160. $result .= $newline . "\n";
  161. return ($result);
  162. }
  163. /**
  164. * Return Radio box Web From element
  165. *
  166. * @param string $name name of element
  167. * @param string $label text label for input
  168. * @param string $value current value
  169. * @param bool $br append new line - bool
  170. * @param bool $checked is checked? - bool
  171. *
  172. * @return string
  173. */
  174. function la_RadioInput($name, $label = '', $value = '', $br = false, $checked = false) {
  175. $inputid = la_InputId();
  176. if ($br) {
  177. $newline = '<br>';
  178. } else {
  179. $newline = '';
  180. }
  181. if ($checked) {
  182. $check = 'checked=""';
  183. } else {
  184. $check = '';
  185. }
  186. $result = '<input type="radio" name="' . $name . '" value="' . $value . '" id="' . $inputid . '" ' . $check . '>' . "\n";
  187. if ($label != '') {
  188. $result .= ' <label for="' . $inputid . '">' . __($label) . '</label>' . "\n";
  189. }
  190. $result .= $newline . "\n";
  191. return ($result);
  192. }
  193. /**
  194. * Return check box Web From element
  195. *
  196. * @param string $name name of element
  197. * @param string $label text label for input
  198. * @param bool $br append new line
  199. * @param bool $checked is checked?
  200. * @param string $CtrlID
  201. * @param string $CtrlClass
  202. *
  203. * @return string
  204. *
  205. */
  206. function la_CheckInput($name, $label = '', $br = false, $checked = false, $CtrlID = '', $CtrlClass = '', $options = '', $labelOptions = '') {
  207. $inputid = ((empty($CtrlID)) ? 'ChkBox_' . la_InputId() : $CtrlID);
  208. $inputClass = ((empty($CtrlClass)) ? '' : ' class="' . $CtrlClass . '" ');
  209. if ($br) {
  210. $newline = '<br>';
  211. } else {
  212. $newline = '';
  213. }
  214. if ($checked) {
  215. $check = 'checked=""';
  216. } else {
  217. $check = '';
  218. }
  219. $result = '<input type="checkbox" id="' . $inputid . '" ' . $inputClass . 'name="' . $name . '" ' . $check . ' ' . $options . ' />';
  220. if ($label != '') {
  221. $result .= ' <label for="' . $inputid . '" ' . $labelOptions . '>' . __($label) . '</label>' . "\n";
  222. }
  223. $result .= $newline . "\n";
  224. return ($result);
  225. }
  226. /**
  227. * Return textarea Web From element
  228. *
  229. * @param string $name name of element
  230. * @param string $label text label for input
  231. * @param string $value value for element
  232. * @param bool $br append new line - bool
  233. * @param string $size size in format "10x20"
  234. *
  235. * @return string
  236. */
  237. function la_TextArea($name, $label = '', $value = '', $br = false, $size = '') {
  238. $inputid = la_InputId();
  239. //set columns and rows count
  240. if ($size != '') {
  241. $sizexplode = explode('x', $size);
  242. $input_size = 'cols="' . $sizexplode[0] . '" rows="' . $sizexplode[1] . '" ';
  243. } else {
  244. $input_size = '';
  245. }
  246. if ($br) {
  247. $newline = '<br>';
  248. } else {
  249. $newline = '';
  250. }
  251. $result = '<textarea name="' . $name . '" ' . $input_size . ' id="' . $inputid . '">' . $value . '</textarea>' . "\n";
  252. if ($label != '') {
  253. $result .= ' <label for="' . $inputid . '">' . __($label) . '</label>' . "\n";
  254. ;
  255. }
  256. $result .= $newline . "\n";
  257. return ($result);
  258. }
  259. /**
  260. * Return hidden input web form element
  261. *
  262. * @param string $name name of element
  263. * @param string s$value value for input
  264. *
  265. * @return string
  266. */
  267. function la_HiddenInput($name, $value = '') {
  268. $result = '<input type="hidden" name="' . $name . '" value="' . $value . '">';
  269. return ($result);
  270. }
  271. /**
  272. * Return submit web form element
  273. *
  274. * @param string $value text label for button
  275. *
  276. * @return string
  277. */
  278. function la_Submit($value, $class = '') {
  279. $result = '<input type="submit" class= "' . $class . '" value="' . __($value) . '">';
  280. return ($result);
  281. }
  282. /**
  283. * Return select Web From element
  284. *
  285. * @param string $name name of element
  286. * @param array $params array of elements $value=>$option
  287. * @param string $label text label for input
  288. * @param string $selected selected $value for selector
  289. * @param string $br append new line - bool
  290. *
  291. * @return string
  292. */
  293. function la_Selector($name, $params, $label, $selected = '', $br = false) {
  294. $inputid = la_InputId();
  295. if ($br) {
  296. $newline = '<br>';
  297. } else {
  298. $newline = '';
  299. }
  300. $result = '<select name="' . $name . '" id="' . $inputid . '">';
  301. if (!empty($params)) {
  302. foreach ($params as $value => $eachparam) {
  303. $sel_flag = '';
  304. if ($selected != '') {
  305. if ($selected == $value) {
  306. $sel_flag = 'SELECTED';
  307. }
  308. }
  309. $result .= '<option value="' . $value . '" ' . $sel_flag . '>' . $eachparam . '</option>' . "\n";
  310. }
  311. }
  312. $result .= '</select>' . "\n";
  313. if ($label != '') {
  314. $result .= '<label for="' . $inputid . '">' . __($label) . '</label>';
  315. }
  316. $result .= $newline . "\n";
  317. return ($result);
  318. }
  319. /**
  320. * Return Month select Web From element
  321. *
  322. * @param string $name name of element
  323. * @param string $label text label for input
  324. * @param string $selected selected $value for selector
  325. * @param string $br append new line - bool
  326. *
  327. * @return string
  328. *
  329. */
  330. function la_MonthSelector($name, $label, $selected = '', $br = false) {
  331. $allmonth = months_array();
  332. $params = array();
  333. //localize months
  334. foreach ($allmonth as $monthnum => $monthname) {
  335. $params[$monthnum] = rcms_date_localise($monthname);
  336. }
  337. $inputid = la_InputId();
  338. if ($br) {
  339. $newline = '<br>';
  340. } else {
  341. $newline = '';
  342. }
  343. $result = '<select name="' . $name . '" id="' . $inputid . '">';
  344. if (!empty($params)) {
  345. foreach ($params as $value => $eachparam) {
  346. $sel_flag = '';
  347. if ($selected != '') {
  348. if ($selected == $value) {
  349. $sel_flag = 'SELECTED';
  350. }
  351. }
  352. $result .= '<option value="' . $value . '" ' . $sel_flag . '>' . $eachparam . '</option>' . "\n";
  353. }
  354. }
  355. $result .= '</select>' . "\n";
  356. if ($label != '') {
  357. $result .= '<label for="' . $inputid . '">' . __($label) . '</label>';
  358. }
  359. $result .= $newline . "\n";
  360. return ($result);
  361. }
  362. /**
  363. * Return Year select Web From element
  364. *
  365. * @param string $name name of element
  366. * @param string $label text label for input
  367. * @param string $br append new line - bool
  368. * @return string
  369. *
  370. */
  371. function la_YearSelector($name, $label = '', $br = false) {
  372. $curyear = curyear();
  373. $inputid = la_InputId();
  374. $count = 5;
  375. if ($br) {
  376. $newline = '<br>';
  377. } else {
  378. $newline = '';
  379. }
  380. $selector = '<select name="' . $name . '">';
  381. for ($i = 0; $i < $count; $i++) {
  382. $selector .= '<option value="' . ($curyear - $i) . '">' . ($curyear - $i) . '</option>';
  383. }
  384. $selector .= '</select>';
  385. if ($label != '') {
  386. $selector .= '<label for="' . $inputid . '">' . __($label) . '</label>';
  387. }
  388. $selector .= $newline;
  389. return($selector);
  390. }
  391. /**
  392. * Check for POST have needed variables
  393. *
  394. * @param array $params array of POST variables to check
  395. * @return bool
  396. *
  397. */
  398. function la_CheckPost($params) {
  399. $result = true;
  400. if (!empty($params)) {
  401. foreach ($params as $eachparam) {
  402. if (isset($_POST[$eachparam])) {
  403. if (empty($_POST[$eachparam])) {
  404. $result = false;
  405. }
  406. } else {
  407. $result = false;
  408. }
  409. }
  410. }
  411. return ($result);
  412. }
  413. /**
  414. * Check for GET have needed variables
  415. *
  416. * @param array $params array of GET variables to check
  417. *
  418. * @return bool
  419. *
  420. */
  421. function la_CheckGet($params) {
  422. $result = true;
  423. if (!empty($params)) {
  424. foreach ($params as $eachparam) {
  425. if (isset($_GET[$eachparam])) {
  426. if (empty($_GET[$eachparam])) {
  427. $result = false;
  428. }
  429. } else {
  430. $result = false;
  431. }
  432. }
  433. }
  434. return ($result);
  435. }
  436. /**
  437. * Construct HTML table row element
  438. *
  439. * @param string $cells table row cells
  440. * @param string $class table row class
  441. *
  442. * @return string
  443. *
  444. */
  445. function la_TableRow($cells, $class = '') {
  446. if ($class != '') {
  447. $rowclass = 'class="' . $class . '"';
  448. } else {
  449. $rowclass = '';
  450. }
  451. $result = '<tr ' . $rowclass . '>' . $cells . '</tr>' . "\n";
  452. return ($result);
  453. }
  454. /**
  455. * Construct HTML table cell element
  456. *
  457. * @param string $data table cell data
  458. * @param string $width width of cell element
  459. * @param string $class table cell class
  460. * @param string $customkey table cell custom param
  461. *
  462. * @return string
  463. */
  464. function la_TableCell($data, $width = '', $class = '', $customkey = '') {
  465. if ($width != '') {
  466. $cellwidth = 'width="' . $width . '"';
  467. } else {
  468. $cellwidth = '';
  469. }
  470. if ($class != '') {
  471. $cellclass = 'class="' . $class . '"';
  472. } else {
  473. $cellclass = '';
  474. }
  475. if ($customkey != '') {
  476. $customkey = $customkey;
  477. } else {
  478. $customkey = '';
  479. }
  480. $result = '<td ' . $cellwidth . ' ' . $cellclass . ' ' . $customkey . '>' . $data . '</td>' . "\n";
  481. return ($result);
  482. }
  483. /**
  484. * Construct HTML table body
  485. *
  486. * @param string $rows table rows data
  487. * @param string $width width of cell element
  488. * @param string $border table border width
  489. * @param string $class table cell class
  490. *
  491. * @return string
  492. *
  493. */
  494. function la_TableBody($rows, $width = '', $border = '0', $class = '') {
  495. if ($width != '') {
  496. $tablewidth = 'width="' . $width . '"';
  497. } else {
  498. $tablewidth = '';
  499. }
  500. if ($class != '') {
  501. $tableclass = 'class="' . $class . '"';
  502. } else {
  503. $tableclass = '';
  504. }
  505. if ($border != '') {
  506. $tableborder = 'border="' . $border . '"';
  507. } else {
  508. $tableborder = '';
  509. }
  510. $result = '
  511. <table ' . $tablewidth . ' ' . $tableborder . ' ' . $tableclass . ' >
  512. ' . $rows . '
  513. </table>
  514. ';
  515. return ($result);
  516. }
  517. /**
  518. * Returns image body
  519. *
  520. * @param string $url image url
  521. * @param string $title image title
  522. *
  523. * @return string
  524. */
  525. function la_img($url, $title = '') {
  526. if ($title != '') {
  527. $imgtitle = 'title="' . $title . '"';
  528. } else {
  529. $imgtitle = '';
  530. }
  531. $result = '<img src="' . $url . '" ' . $imgtitle . ' border="0">';
  532. return ($result);
  533. }
  534. /**
  535. * Returns image body with some dimensions
  536. *
  537. * @param string $url image url
  538. * @param string $title title attribure for image
  539. * @param string $width image width
  540. * @param string $height image height
  541. *
  542. * @return string
  543. *
  544. */
  545. function la_img_sized($url, $title = '', $width = '', $height = '', $style = '') {
  546. $imgtitle = ($title != '') ? 'title="' . $title . '"' : '';
  547. $imgwidth = ($width != '') ? 'width="' . $width . '"' : '';
  548. $imgheight = ($height != '') ? 'height="' . $height . '"' : '';
  549. $imgstyle = (empty($style)) ? '' : ' style="' . $style . '" ';
  550. $result = '<img src="' . $url . '" ' . $imgtitle . ' ' . $imgwidth . ' ' . $imgheight . $imgstyle . ' border="0">';
  551. return ($result);
  552. }
  553. /**
  554. * Returns some count of delimiters
  555. *
  556. * @param int $count count of delimited rows
  557. *
  558. * @return string
  559. */
  560. function la_delimiter($count = 1) {
  561. $result = '';
  562. for ($i = 0; $i <= $count; $i++) {
  563. $result .= '<br />';
  564. }
  565. return ($result);
  566. }
  567. /**
  568. * Returns some count of non-breaking space symbols
  569. *
  570. * @param int $count
  571. *
  572. * @return string
  573. */
  574. function la_nbsp($count = 1) {
  575. $result = '';
  576. for ($i = 0; $i < $count; $i++) {
  577. $result .= '&nbsp;';
  578. }
  579. return ($result);
  580. }
  581. /**
  582. * Returns some html styled tag
  583. *
  584. * @param string $tag HTML tag entity
  585. * @param string $closed tag is closing?
  586. * @param string $class tag styling class
  587. * @param string $options tag extra options
  588. *
  589. * @return string
  590. */
  591. function la_tag($tag, $closed = false, $class = '', $options = '') {
  592. if (!empty($class)) {
  593. $tagclass = ' class="' . $class . '"';
  594. } else {
  595. $tagclass = '';
  596. }
  597. if ($closed) {
  598. $tagclose = '/';
  599. } else {
  600. $tagclose = '';
  601. }
  602. if ($options != '') {
  603. $tagoptions = $options;
  604. } else {
  605. $tagoptions = '';
  606. }
  607. $result = '<' . $tagclose . $tag . $tagclass . ' ' . $tagoptions . '>';
  608. return ($result);
  609. }
  610. /**
  611. * Returns calendar widget with preset date
  612. *
  613. * @param string $field field name to insert calendar
  614. *
  615. * @return string
  616. *
  617. */
  618. function la_DatePickerPreset($field, $date) {
  619. $inputid = la_InputId();
  620. $us_config = zbs_LoadConfig();
  621. $curlang = $us_config['lang'];
  622. $skinPath = zbs_GetCurrentSkinPath($us_config);
  623. $iconsPath = $skinPath . 'iconz/';
  624. $result = '<script>
  625. $(function() {
  626. $( "#' . $inputid . '" ).datepicker({
  627. showOn: "both",
  628. buttonImage: "' . $iconsPath . 'icon_calendar.gif",
  629. buttonImageOnly: true,
  630. dateFormat: "yy-mm-dd",
  631. showAnim: "slideDown"
  632. });
  633. $.datepicker.regional[\'english\'] = {
  634. closeText: \'Done\',
  635. prevText: \'Prev\',
  636. nextText: \'Next\',
  637. currentText: \'Today\',
  638. monthNames: [\'January\',\'February\',\'March\',\'April\',\'May\',\'June\',
  639. \'July\',\'August\',\'September\',\'October\',\'November\',\'December\'],
  640. monthNamesShort: [\'Jan\', \'Feb\', \'Mar\', \'Apr\', \'May\', \'Jun\',
  641. \'Jul\', \'Aug\', \'Sep\', \'Oct\', \'Nov\', \'Dec\'],
  642. dayNames: [\'Sunday\', \'Monday\', \'Tuesday\', \'Wednesday\', \'Thursday\', \'Friday\', \'Saturday\'],
  643. dayNamesShort: [\'Sun\', \'Mon\', \'Tue\', \'Wed\', \'Thu\', \'Fri\', \'Sat\'],
  644. dayNamesMin: [\'Su\',\'Mo\',\'Tu\',\'We\',\'Th\',\'Fr\',\'Sa\'],
  645. weekHeader: \'Wk\',
  646. dateFormat: \'dd/mm/yy\',
  647. firstDay: 1,
  648. isRTL: false,
  649. showMonthAfterYear: false,
  650. yearSuffix: \'\'};
  651. $.datepicker.regional[\'russian\'] = {
  652. closeText: \'Закрыть\',
  653. prevText: \'&#x3c;Пред\',
  654. nextText: \'След&#x3e;\',
  655. currentText: \'Сегодня\',
  656. monthNames: [\'Январь\',\'Февраль\',\'Март\',\'Апрель\',\'Май\',\'Июнь\',
  657. \'Июль\',\'Август\',\'Сентябрь\',\'Октябрь\',\'Ноябрь\',\'Декабрь\'],
  658. monthNamesShort: [\'Янв\',\'Фев\',\'Мар\',\'Апр\',\'Май\',\'Июн\',
  659. \'Июл\',\'Авг\',\'Сен\',\'Окт\',\'Ноя\',\'Дек\'],
  660. dayNames: [\'воскресенье\',\'понедельник\',\'вторник\',\'среда\',\'четверг\',\'пятница\',\'суббота\'],
  661. dayNamesShort: [\'вск\',\'пнд\',\'втр\',\'срд\',\'чтв\',\'птн\',\'сбт\'],
  662. dayNamesMin: [\'Вс\',\'Пн\',\'Вт\',\'Ср\',\'Чт\',\'Пт\',\'Сб\'],
  663. weekHeader: \'Нед\',
  664. dateFormat: \'dd.mm.yy\',
  665. firstDay: 1,
  666. isRTL: false,
  667. showMonthAfterYear: false,
  668. yearSuffix: \'\'};
  669. $.datepicker.regional[\'ukrainian\'] = {
  670. closeText: \'Закрити\',
  671. prevText: \'&#x3c;\',
  672. nextText: \'&#x3e;\',
  673. currentText: \'Сьогодні\',
  674. monthNames: [\'Січень\',\'Лютий\',\'Березень\',\'Квітень\',\'Травень\',\'Червень\',
  675. \'Липень\',\'Серпень\',\'Вересень\',\'Жовтень\',\'Листопад\',\'Грудень\'],
  676. monthNamesShort: [\'Січ\',\'Лют\',\'Бер\',\'Кві\',\'Тра\',\'Чер\',
  677. \'Лип\',\'Сер\',\'Вер\',\'Жов\',\'Лис\',\'Гру\'],
  678. dayNames: [\'неділя\',\'понеділок\',\'вівторок\',\'середа\',\'четвер\',\'п’ятниця\',\'субота\'],
  679. dayNamesShort: [\'нед\',\'пнд\',\'вів\',\'срд\',\'чтв\',\'птн\',\'сбт\'],
  680. dayNamesMin: [\'Нд\',\'Пн\',\'Вт\',\'Ср\',\'Чт\',\'Пт\',\'Сб\'],
  681. weekHeader: \'Тиж\',
  682. dateFormat: \'dd/mm/yy\',
  683. firstDay: 1,
  684. isRTL: false,
  685. showMonthAfterYear: false,
  686. yearSuffix: \'\'};
  687. $.datepicker.setDefaults($.datepicker.regional[\'' . $curlang . '\']);
  688. });
  689. </script>
  690. <input type="text" id="' . $inputid . '" name="' . $field . '" value="' . $date . '" size="10">
  691. ';
  692. return($result);
  693. }
  694. /**
  695. * Returns modal window JS code
  696. *
  697. * @param string $link
  698. * @param string $title
  699. * @param string $content
  700. * @param string $linkclass
  701. * @param string $width
  702. * @param string $height
  703. *
  704. * @return string
  705. */
  706. function la_modal($link, $title, $content, $linkclass = '', $width = '', $height = '') {
  707. $wid = la_inputid();
  708. //setting link class
  709. if ($linkclass != '') {
  710. $link_class = 'class="' . $linkclass . '"';
  711. } else {
  712. $link_class = '';
  713. }
  714. //setting auto width if not specified
  715. if ($width == '') {
  716. $width = '600';
  717. }
  718. //setting auto width if not specified
  719. if ($height == '') {
  720. $height = '400';
  721. }
  722. $dialog = '
  723. <script type="text/javascript">
  724. $(function() {
  725. $( "#dialog-modal_' . $wid . '" ).dialog({
  726. autoOpen: false,
  727. width: ' . $width . ',
  728. height: ' . $height . ',
  729. modal: true,
  730. show: "drop",
  731. hide: "fold"
  732. });
  733. $( "#opener_' . $wid . '" ).click(function() {
  734. $( "#dialog-modal_' . $wid . '" ).dialog( "open" );
  735. return false;
  736. });
  737. });
  738. </script>
  739. <div id="dialog-modal_' . $wid . '" title="' . $title . '" style="display:none; width:1px; height:1px;">
  740. <p>
  741. ' . $content . '
  742. </p>
  743. </div>
  744. <a href="#" id="opener_' . $wid . '" ' . $link_class . '>' . $link . '</a>
  745. ';
  746. return($dialog);
  747. }
  748. /**
  749. * Returns link that calls new modal window with automatic dimensions by inside content
  750. *
  751. * @param string $link link text
  752. * @param string $title modal window title
  753. * @param string $content modal window content
  754. * @param string $linkclass link class
  755. *
  756. * @return string
  757. *
  758. */
  759. function la_modalAuto($link, $title, $content, $linkclass = '') {
  760. $wid = la_inputid();
  761. //setting link class
  762. if ($linkclass != '') {
  763. $link_class = 'class="' . $linkclass . '"';
  764. } else {
  765. $link_class = '';
  766. }
  767. $width = "'auto'";
  768. $height = "'auto'";
  769. $dialog = '
  770. <script type="text/javascript">
  771. $(function() {
  772. $( "#dialog-modal_' . $wid . '" ).dialog({
  773. autoOpen: false,
  774. width: \'auto\',
  775. height: \'auto\',
  776. modal: true,
  777. show: "drop",
  778. hide: "fold"
  779. });
  780. $( "#opener_' . $wid . '" ).click(function() {
  781. $( "#dialog-modal_' . $wid . '" ).dialog( "open" );
  782. return false;
  783. });
  784. });
  785. </script>
  786. <div id="dialog-modal_' . $wid . '" title="' . $title . '" style="display:none; width:1px; height:1px;">
  787. <p>
  788. ' . $content . '
  789. </p>
  790. </div>
  791. <a href="#" id="opener_' . $wid . '" ' . $link_class . '>' . $link . '</a>
  792. ';
  793. return($dialog);
  794. }
  795. /**
  796. * Returns new opened modal window with some content
  797. *
  798. * @param string $title modal window title
  799. * @param string $content modal window content
  800. * @param string $width modal window width
  801. * @param string $height modal window height
  802. * @return string
  803. *
  804. */
  805. function la_modalOpened($title, $content, $width = '', $height = '') {
  806. $wid = la_inputid();
  807. //setting auto width if not specified
  808. if ($width == '') {
  809. $width = "'auto'";
  810. }
  811. //setting auto width if not specified
  812. if ($height == '') {
  813. $height = "'auto'";
  814. }
  815. $dialog = '
  816. <script type="text/javascript">
  817. $(function() {
  818. $( "#dialog-modal_' . $wid . '" ).dialog({
  819. autoOpen: true,
  820. width: ' . $width . ',
  821. height: ' . $height . ',
  822. modal: true,
  823. show: "drop",
  824. hide: "fold",
  825. create: function( event, ui ) {
  826. $(this).css("maxWidth", "800px");
  827. }
  828. });
  829. $( "#opener_' . $wid . '" ).click(function() {
  830. $( "#dialog-modal_' . $wid . '" ).dialog( "open" );
  831. return false;
  832. });
  833. });
  834. </script>
  835. <div id="dialog-modal_' . $wid . '" title="' . $title . '" style="display:none; width:1px; height:1px;">
  836. <p>
  837. ' . $content . '
  838. </p>
  839. </div>
  840. ';
  841. return($dialog);
  842. }
  843. /**
  844. * Returns JS confirmation url
  845. *
  846. * @param string $url URL if confirmed
  847. * @param string $title link title
  848. * @param string $alerttext alert text
  849. * @return string
  850. *
  851. */
  852. function la_JSAlert($url, $title, $alerttext) {
  853. $result = '<a onclick="if(!confirm(\'' . __($alerttext) . '\')) { return false;}" href="' . $url . '">' . $title . '</a>';
  854. return ($result);
  855. }
  856. /**
  857. * Returns JS confirmation url with some applied class
  858. *
  859. * @param string $url URL if confirmed
  860. * @param string $title link title
  861. * @param string $alerttext alert text
  862. * @param string $functiontorun function name with parameters which must exist on a page
  863. *
  864. * @return string
  865. */
  866. function la_JSAlertStyled($url, $title, $alerttext, $class = '', $functiontorun = '') {
  867. $class = (!empty($class)) ? 'class="' . $class . '"' : '';
  868. if (empty($functiontorun)) {
  869. $result = '<a onclick="if(!confirm(\'' . __($alerttext) . '\')) { return false;}" href="' . $url . '" ' . $class . '>' . $title . '</a>';
  870. } else {
  871. $result = '<a onclick="if(!confirm(\'' . __($alerttext) . '\')) { return false;} else { ' . $functiontorun . '; }" href="' . $url . '" ' . $class . '>' . $title . '</a>';
  872. }
  873. return ($result);
  874. }
  875. /**
  876. * Returns confirmation dialog to navigate to some URL
  877. *
  878. * @param string $url
  879. * @param string $title
  880. * @param string $alerttext
  881. * @param string $class
  882. * @param string $cancelUrl
  883. *
  884. * @return string
  885. */
  886. function la_ConfirmDialog($url, $title, $alerttext, $class = '', $cancelUrl = '') {
  887. $result = '';
  888. $dialog = __($alerttext);
  889. $dialog .= la_tag('br');
  890. $dialog .= la_tag('center', false);
  891. $dialog .= la_Link($url, __('Agree'), false, 'anreadbutton');
  892. if ($cancelUrl) {
  893. $dialog .= la_Link($cancelUrl, __('Cancel'), false, 'anunreadbutton');
  894. }
  895. $dialog .= la_tag('center', true);
  896. $result .= la_modalAuto($title, __($title), $dialog, $class);
  897. return($result);
  898. }
  899. ?>