api.customfields.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  1. <?php
  2. /**
  3. * Custom profile fields implementation
  4. */
  5. class CustomFields {
  6. /**
  7. * Contains system alter config as key=>value
  8. *
  9. * @var array
  10. */
  11. protected $altCfg = array();
  12. /**
  13. * Contains available custom fileds types as TYPE=>description
  14. *
  15. * @var array
  16. */
  17. protected $typesAvailable = array();
  18. /**
  19. * Current instance user login
  20. *
  21. * @var string
  22. */
  23. protected $login = '';
  24. /**
  25. * Custom Fileds types database abstraction layer
  26. *
  27. * @var object
  28. */
  29. protected $typesDb = '';
  30. /**
  31. * Custom Fileds item records database abstraction layer
  32. *
  33. * @var object
  34. */
  35. protected $itemsDb = '';
  36. /**
  37. * System message helper instance placeholder
  38. *
  39. * @var object
  40. */
  41. protected $messages = '';
  42. /**
  43. * Contains all available custom profile fileds types as id=>typeData
  44. *
  45. * @var array
  46. */
  47. protected $allTypes = array();
  48. /**
  49. * Contains all current instance user custom fields data as typeId=>cfData
  50. *
  51. * @var array
  52. */
  53. protected $userFieldsData = array();
  54. /**
  55. * Some predefined stuff like URLs, routes etc
  56. */
  57. const TABLE_TYPES = 'cftypes';
  58. const TABLE_ITEMS = 'cfitems';
  59. const PROUTE_NEWTYPE = 'newtype';
  60. const PROUTE_NEWNAME = 'newname';
  61. const PROUTE_EDID = 'editid';
  62. const PROUTE_EDTYPE = 'edittype';
  63. const PROUTE_EDNAME = 'editname';
  64. const ROUTE_DELETE = 'deletetypeid';
  65. const ROUTE_EDIT = 'edittypeid';
  66. const PROUTE_MODTYPE = 'modcftypeid';
  67. const PROUTE_MODLOGIN = 'modcflogin';
  68. const PROUTE_MODCONTENT = 'modcfcontent';
  69. const PROUTE_SEARCHTYPEID = 'cftypeid';
  70. const PROUTE_SEARCHQUERY = 'cfquery';
  71. const PHOTOSTORAGE_SCOPE = 'CFITEMS';
  72. const PHOTOSTORAGE_ITEMID_DELIMITER = '|';
  73. const FILESTORAGE_SCOPE = 'CFITEMS';
  74. const FILESTORAGE_ITEMID_DELIMITER = '|';
  75. const URL_ME = '?module=cftypes';
  76. const URL_EDIT_BACK = '?module=useredit&username=';
  77. const URL_PHOTOUPL = '?module=photostorage&scope=CFITEMS&mode=list&itemid=';
  78. const URL_FILEUPL = '?module=filestorage&scope=CFITEMS&mode=list&itemid=';
  79. // _
  80. // {` `'-.
  81. // { \ (\._
  82. // { | / o'.
  83. // `} /.`'.___.'
  84. // { .' , \_/`\
  85. // } /`_ '-. '=/
  86. // { .' `\;`'`
  87. // { ; /_
  88. // '-'...-;`__\
  89. //
  90. // ^^^^ A CE BILOCHKA
  91. /**
  92. * Creates new CF instance
  93. *
  94. * @param string $login
  95. */
  96. public function __construct($login = '') {
  97. $this->loadAltCfg();
  98. $this->initMessages();
  99. $this->setAvailableTypes();
  100. $this->setLogin($login);
  101. $this->initDb();
  102. $this->loadTypes();
  103. if (!empty($this->login)) {
  104. $this->loadUserItems();
  105. }
  106. }
  107. /**
  108. * Inits database absctraction layer for further usage
  109. *
  110. * @return void
  111. */
  112. protected function initDb() {
  113. $this->typesDb = new NyanORM(self::TABLE_TYPES);
  114. $this->itemsDb = new NyanORM(self::TABLE_ITEMS);
  115. }
  116. /**
  117. * Loads system alter config to protected property
  118. *
  119. * @global object $ubillingConfig
  120. *
  121. * @return void
  122. */
  123. protected function loadAltCfg() {
  124. global $ubillingConfig;
  125. $this->altCfg = $ubillingConfig->getAlter();
  126. }
  127. /**
  128. * Inits system messages helper protected instance
  129. *
  130. * @return void
  131. */
  132. protected function initMessages() {
  133. $this->messages = new UbillingMessageHelper();
  134. }
  135. /**
  136. * Loads existing CF types from database
  137. *
  138. * @return void
  139. */
  140. protected function loadTypes() {
  141. $this->allTypes = $this->typesDb->getAll('id');
  142. }
  143. /**
  144. * Sets available custom fields types
  145. *
  146. * @return void
  147. */
  148. protected function setAvailableTypes() {
  149. //basic types
  150. $this->typesAvailable = array(
  151. 'VARCHAR' => __('String'),
  152. 'TRIGGER' => __('Trigger'),
  153. 'TEXT' => __('Text'),
  154. 'INT' => __('Integer'),
  155. 'FLOAT' => __('Float'),
  156. 'FINANCE' => __('Finance'),
  157. 'NETWORK' => __('Network'),
  158. 'URL' => __('URL'),
  159. 'DATE' => __('Date'),
  160. 'TIME' => __('Time'),
  161. 'COLOR' => __('Color'),
  162. 'LIST' => __('List')
  163. );
  164. //optional types
  165. if ($this->altCfg['PHOTOSTORAGE_ENABLED']) {
  166. $this->typesAvailable['PHOTO'] = __('Image');
  167. }
  168. if ($this->altCfg['FILESTORAGE_ENABLED']) {
  169. $this->typesAvailable['FILE'] = __('File');
  170. }
  171. }
  172. /**
  173. * Sets current instance user login
  174. *
  175. * @param string $login
  176. *
  177. * @return void
  178. */
  179. protected function setLogin($login = '') {
  180. if (!empty($login)) {
  181. $this->login = ubRouting::filters($login, 'mres');
  182. }
  183. }
  184. /**
  185. * Returns all available CF types as id=>typeData
  186. *
  187. * @return array
  188. */
  189. public function getTypesAll() {
  190. return($this->allTypes);
  191. }
  192. /**
  193. * Returns all available fields data for all users
  194. *
  195. * @return array
  196. */
  197. public function getAllFieldsData() {
  198. $result = array();
  199. if (!empty($this->allTypes)) {
  200. $result = $this->itemsDb->getAll();
  201. }
  202. return($result);
  203. }
  204. /**
  205. * Returns existing CF type data by its typeId
  206. *
  207. * @param int $typeId Existing CF type database ID
  208. *
  209. * @return array
  210. */
  211. protected function getTypeData($typeId) {
  212. $result = array();
  213. if (isset($this->allTypes[$typeId])) {
  214. $result = $this->allTypes[$typeId];
  215. }
  216. return($result);
  217. }
  218. /**
  219. * Loads current instance users items data into protected property
  220. *
  221. * @return void
  222. */
  223. protected function loadUserItems() {
  224. if (!empty($this->login)) {
  225. if (!empty($this->allTypes)) {
  226. $this->itemsDb->where('login', '=', $this->login);
  227. $this->userFieldsData = $this->itemsDb->getAll('typeid');
  228. }
  229. }
  230. }
  231. /**
  232. * Flushes all of assigned to users CFs data from database
  233. *
  234. * @param int $typeId Existing CF type database ID
  235. *
  236. * @return void
  237. */
  238. protected function flushType($typeId) {
  239. $typeId = ubRouting::filters($typeId, 'int');
  240. $this->itemsDb->where('typeid', '=', $typeId);
  241. $this->itemsDb->delete();
  242. log_register('CFTYPE FLUSH [' . $typeId . ']');
  243. }
  244. /**
  245. * Deletes CF type from database by its ID and flushes assigned
  246. *
  247. * @param int $typeId Existing CF type database ID
  248. *
  249. * @return void
  250. */
  251. public function deleteType($typeId) {
  252. $typeId = ubRouting::filters($typeId, 'int');
  253. $this->typesDb->where('id', '=', $typeId);
  254. $this->typesDb->delete();
  255. log_register('CFTYPE DELETE [' . $typeId . ']');
  256. $this->flushType($typeId);
  257. }
  258. /**
  259. * Deletes all of CF items from database associated with some user
  260. *
  261. * @return void
  262. */
  263. public function flushAllUserFieldsData() {
  264. if (!empty($this->login)) {
  265. $this->itemsDb->where('login', '=', $this->login);
  266. $this->itemsDb->delete();
  267. log_register('CF FLUSH (' . $this->login . ')');
  268. }
  269. }
  270. /**
  271. * Creates new CF type in database
  272. *
  273. * @param string $type Type of the CF (VARCHAR, TRIGGER, TEXT etc)
  274. * @param string $name Name of the custom field for display
  275. *
  276. * @return void
  277. */
  278. public function createType($type, $name) {
  279. $type = ubRouting::filters($type, 'mres');
  280. $name = ubRouting::filters($name, 'mres');
  281. if ((!empty($name)) AND ( !empty($type))) {
  282. $this->typesDb->data('type', $type);
  283. $this->typesDb->data('name', $name);
  284. $this->typesDb->create();
  285. $newId = $this->typesDb->getLastId();
  286. log_register('CFTYPE ADD `' . $type . '` NAME `' . $name . '` AS [' . $newId . ']');
  287. }
  288. }
  289. /**
  290. * Returns Custom Field Type creation form
  291. *
  292. * @return string
  293. */
  294. public function renderTypeCreationForm() {
  295. $result = '';
  296. $inputs = wf_Selector(self::PROUTE_NEWTYPE, $this->typesAvailable, __('Field type'), '', true);
  297. $inputs .= wf_TextInput(self::PROUTE_NEWNAME, __('Field name'), '', true, 15);
  298. $inputs .= wf_Submit(__('Create'));
  299. $result = wf_Form('', 'POST', $inputs, 'glamour');
  300. return($result);
  301. }
  302. /**
  303. * Returns CF type editing form
  304. *
  305. * @param int $typeId Existing CF type ID
  306. *
  307. * @return string
  308. */
  309. public function renderTypeEditForm($typeId) {
  310. $result = '';
  311. $typeId = ubRouting::filters($typeId, 'int');
  312. $typeData = $this->getTypeData($typeId);
  313. if (!empty($typeData)) {
  314. $inputs = wf_HiddenInput('editid', $typeId);
  315. $inputs .= wf_Selector('edittype', $this->typesAvailable, 'Field type', $typeData['type'], true);
  316. $inputs .= wf_TextInput('editname', 'Field name', $typeData['name'], true);
  317. $inputs .= wf_Submit('Edit');
  318. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  319. } else {
  320. $result .= $this->messages->getStyledMessage(__('Something went wrong') . ' [' . $typeId . '] ' . __('Not exists'), 'error');
  321. }
  322. $result .= wf_delimiter();
  323. $result .= wf_BackLink(self::URL_ME);
  324. return($result);
  325. }
  326. /**
  327. * Saves CF type editing form into database
  328. *
  329. * @return void
  330. */
  331. public function saveType() {
  332. if (ubRouting::checkPost(array(self::PROUTE_EDID, self::PROUTE_EDTYPE, self::PROUTE_EDNAME))) {
  333. $id = ubRouting::post(self::PROUTE_EDID, 'int');
  334. $type = ubRouting::post(self::PROUTE_EDTYPE, 'mres');
  335. $name = ubRouting::post(self::PROUTE_EDNAME);
  336. $nameF = ubRouting::filters($name, 'mres');
  337. if (isset($this->allTypes[$id])) {
  338. $this->typesDb->data('type', $type);
  339. $this->typesDb->data('name', $nameF);
  340. $this->typesDb->where('id', '=', $id);
  341. $this->typesDb->save();
  342. log_register('CFTYPE CHANGE [' . $id . '] NAME `' . $name . '`');
  343. }
  344. }
  345. }
  346. /**
  347. * Returns human-readable type description
  348. *
  349. * @param string $type
  350. *
  351. * @return string
  352. */
  353. protected function getTypeNameDesc($type) {
  354. $result = '';
  355. if (isset($this->typesAvailable[$type])) {
  356. $result .= $this->typesAvailable[$type];
  357. } else {
  358. $result .= __('Disabled');
  359. }
  360. return($result);
  361. }
  362. /**
  363. * Renders list of available CF types
  364. *
  365. * @return string
  366. */
  367. public function renderTypesList() {
  368. $result = '';
  369. if (!empty($this->allTypes)) {
  370. $cells = wf_TableCell(__('ID'));
  371. $cells .= wf_TableCell(__('Field type'));
  372. $cells .= wf_TableCell(__('Field name'));
  373. $cells .= wf_TableCell(__('Actions'));
  374. $rows = wf_TableRow($cells, 'row1');
  375. foreach ($this->allTypes as $io => $each) {
  376. $cells = wf_TableCell($each['id']);
  377. $cells .= wf_TableCell($this->getTypeNameDesc($each['type']));
  378. $cells .= wf_TableCell($each['name']);
  379. $urlDelete = self::URL_ME . '&' . self::ROUTE_DELETE . '=' . $each['id'];
  380. $urlEdit = self::URL_ME . '&' . self::ROUTE_EDIT . '=' . $each['id'];
  381. $cancelUrl = self::URL_ME;
  382. $deleteTitle = __('Delete') . ' ' . $each['name'] . '?';
  383. $deleteAlert = $this->messages->getDeleteAlert() . '. ' . __('All related data will be deleted too');
  384. $actionControls = wf_ConfirmDialog($urlDelete, web_delete_icon(), $deleteAlert, '', $cancelUrl, $deleteTitle) . ' ';
  385. $actionControls .= wf_JSAlert($urlEdit, web_edit_icon(), $this->messages->getEditAlert());
  386. $cells .= wf_TableCell($actionControls);
  387. $rows .= wf_TableRow($cells, 'row5');
  388. }
  389. $result .= wf_TableBody($rows, '100%', 0, 'sortable');
  390. } else {
  391. $result .= $this->messages->getStyledMessage(__('Nothing to show'), 'info');
  392. }
  393. return($result);
  394. }
  395. /**
  396. * Returns preformatted view of CF content preprocessed depends by its type
  397. *
  398. * @param string $fieldType Type of the data (VARCHAR, TRIGGER, TEXT etc)
  399. * @param string $data Data of CF
  400. * @param int $typeId CF type ID
  401. *
  402. * @return string
  403. */
  404. protected function renderField($fieldType, $data, $typeId = 0) {
  405. if ($fieldType == 'TRIGGER') {
  406. $data = ($data) ? wf_img_sized('skins/icon_active.gif', '', '12') : wf_img_sized('skins/icon_inactive.gif', '', '12');
  407. }
  408. if ($fieldType == 'TEXT') {
  409. $data = nl2br($data);
  410. }
  411. if ($fieldType == 'URL') {
  412. $data = wf_Link($data, $data, false, '', 'target="_BLANK"');
  413. }
  414. if ($fieldType == 'COLOR') {
  415. if (!empty($data)) {
  416. $data = wf_tag('color', false, '', 'style="color:' . $data . '"') . $data . wf_tag('font', true);
  417. }
  418. }
  419. if ($fieldType == 'PHOTO') {
  420. if (!empty($typeId) AND ! empty($this->login)) {
  421. if ($this->altCfg['PHOTOSTORAGE_ENABLED']) {
  422. $photostorage = new PhotoStorage(self::PHOTOSTORAGE_SCOPE, $this->login . self::PHOTOSTORAGE_ITEMID_DELIMITER . $typeId);
  423. $data = $photostorage->renderImagesRaw();
  424. }
  425. }
  426. }
  427. if ($fieldType == 'FILE') {
  428. if (!empty($typeId) AND ! empty($this->login)) {
  429. if ($this->altCfg['FILESTORAGE_ENABLED']) {
  430. $fileStorage = new FileStorage(self::FILESTORAGE_SCOPE, $this->login . self::FILESTORAGE_ITEMID_DELIMITER . $typeId);
  431. $data = $fileStorage->renderFilesPreview(false, '', '', 64);
  432. }
  433. }
  434. }
  435. return ($data);
  436. }
  437. /**
  438. * Returns user custom field content depends on its type
  439. *
  440. * @param int $typeId existing CF type ID
  441. *
  442. * @return string|void
  443. */
  444. public function getUserFieldContent($typeId) {
  445. $result = '';
  446. if (isset($this->userFieldsData[$typeId])) {
  447. $result .= $this->userFieldsData[$typeId]['content'];
  448. }
  449. return($result);
  450. }
  451. /**
  452. * Returns available user custom fields for user profile
  453. *
  454. * @result
  455. */
  456. public function renderUserFields() {
  457. $result = '';
  458. if (!empty($this->login)) {
  459. if (!empty($this->allTypes)) {
  460. $rows = '';
  461. foreach ($this->allTypes as $io => $eachType) {
  462. $cells = wf_TableCell($this->renderTypeName($eachType['id']), '30%', 'row2', 'valign="top"');
  463. $cells .= wf_TableCell($this->renderField($eachType['type'], $this->getUserFieldContent($eachType['id']), $eachType['id']), '', 'row3', 'valign="top"');
  464. $rows .= wf_TableRow($cells);
  465. }
  466. $result = wf_TableBody($rows, '100%', 0, '', UserProfile::MAIN_TABLE_STYLE);
  467. }
  468. }
  469. return($result);
  470. }
  471. /**
  472. * Sets content of custom field for current instance user
  473. *
  474. * @param string $login
  475. * @param int $typeId
  476. * @param string $content
  477. * @throws Exception
  478. *
  479. * @return void
  480. */
  481. protected function setFieldContent($login, $typeId, $content) {
  482. $typeId = ubRouting::filters($typeId, 'int');
  483. $contentF = ubRouting::filters($content, 'mres');
  484. if (!empty($login)) {
  485. if (isset($this->allTypes[$typeId])) {
  486. $this->itemsDb->data('typeid', $typeId);
  487. $this->itemsDb->data('login', $login);
  488. $this->itemsDb->data('content', $contentF);
  489. //update or create field content
  490. if (isset($this->userFieldsData[$typeId])) {
  491. $currentFieldId = $this->userFieldsData[$typeId]['id'];
  492. $this->itemsDb->where('id', '=', $currentFieldId);
  493. $this->itemsDb->save();
  494. } else {
  495. $this->itemsDb->create();
  496. }
  497. $logContent = (strlen($content) < 20) ? $content : substr($content, 0, 20) . '..';
  498. log_register('CF SET (' . $login . ') TYPE [' . $typeId . ']' . ' ON `' . $logContent . '`');
  499. } else {
  500. throw new Exception('EX_TYPEID_NOT_EXISTS');
  501. }
  502. } else {
  503. throw new Exception('EX_LOGIN_EMPTY');
  504. }
  505. }
  506. /**
  507. * Returns existing type name, may be cleaned from technical data
  508. *
  509. * @param int $typeId
  510. *
  511. * @return string
  512. */
  513. public function renderTypeName($typeId) {
  514. $result = '';
  515. if (isset($this->allTypes[$typeId])) {
  516. $typeData = $this->allTypes[$typeId];
  517. $typeName = $typeData['name'];
  518. //some optional postprocessing
  519. if ($typeData['type'] == 'LIST') {
  520. if (ispos($typeName, '[') AND ispos($typeName, ']')) {
  521. $rawList = zb_ParseTagData('[', ']', $typeName);
  522. $typeName = str_replace('[' . $rawList . ']', '', $typeName);
  523. }
  524. }
  525. $result = $typeName;
  526. } else {
  527. $result .= '[' . $typeId . '] ' . __('Not exists');
  528. }
  529. return($result);
  530. }
  531. /**
  532. * Renders CF editor controller
  533. *
  534. * @return void
  535. */
  536. public function renderUserFieldEditor() {
  537. global $billing;
  538. $result = '';
  539. //editing subroutine
  540. if (ubRouting::checkPost(self::PROUTE_MODTYPE)) {
  541. $this->setFieldContent(ubRouting::post(self::PROUTE_MODLOGIN), ubRouting::post(self::PROUTE_MODTYPE), ubRouting::post(self::PROUTE_MODCONTENT));
  542. //is user reset required after field change?
  543. if ($this->altCfg['RESETONCFCHANGE']) {
  544. $billing->resetuser($this->login);
  545. log_register('RESET User (' . $this->login . ')');
  546. }
  547. ubRouting::nav(self::URL_EDIT_BACK . $this->login);
  548. }
  549. if (!empty($this->allTypes)) {
  550. $cells = wf_TableCell(__('Field name'));
  551. $cells .= wf_TableCell(__('Current value'));
  552. $cells .= wf_TableCell(__('Edit'));
  553. $rows = wf_TableRow($cells, 'row1');
  554. foreach ($this->allTypes as $io => $eachType) {
  555. $cells = wf_TableCell($this->renderTypeName($eachType['id']), '', '', 'valign="top"');
  556. $cells .= wf_TableCell($this->renderField($eachType['type'], $this->getUserFieldContent($eachType['id']), $eachType['id']), '', '', 'valign="top"');
  557. $cells .= wf_TableCell($this->renderTypeController($this->login, $eachType['type'], $eachType['id']), '', '', 'valign="top"');
  558. $rows .= wf_TableRow($cells, 'row3');
  559. }
  560. $result .= wf_TableBody($rows, '100%', 0, '', UserProfile::MAIN_TABLE_STYLE);
  561. }
  562. return($result);
  563. }
  564. /**
  565. * Returns editing controller for CF assigned to user
  566. *
  567. * @param string $login Existing user login
  568. * @param string $type Type of CF to return control
  569. * @param int $typeId Type ID for change
  570. *
  571. * @return string
  572. */
  573. protected function renderTypeController($login, $type, $typeId) {
  574. $result = '';
  575. $type = ubRouting::filters($type, 'vf');
  576. $typeId = ubRouting::filters($typeId, 'int');
  577. $currentFieldContent = '';
  578. if (isset($this->userFieldsData[$typeId])) {
  579. $currentFieldContent = $this->userFieldsData[$typeId]['content'];
  580. }
  581. //basic forms inputs
  582. $inputs = wf_HiddenInput(self::PROUTE_MODTYPE, $typeId);
  583. $inputs .= wf_HiddenInput(self::PROUTE_MODLOGIN, $login);
  584. if ($type == 'VARCHAR') {
  585. $inputs .= wf_TextInput(self::PROUTE_MODCONTENT, '', $currentFieldContent, false, 20);
  586. $inputs .= wf_Submit(__('Save'));
  587. $result = wf_Form("", 'POST', $inputs, '');
  588. }
  589. if ($type == 'TRIGGER') {
  590. $triggerOpts = array(1 => __('Yes'), 0 => __('No'));
  591. $inputs .= wf_Selector(self::PROUTE_MODCONTENT, $triggerOpts, '', $currentFieldContent, false);
  592. $inputs .= wf_Submit(__('Save'));
  593. $result = wf_Form("", 'POST', $inputs, '');
  594. }
  595. if ($type == 'TEXT') {
  596. $inputs .= wf_TextArea(self::PROUTE_MODCONTENT, '', $currentFieldContent, true, '45x5');
  597. $inputs .= wf_Submit(__('Save'));
  598. $result = wf_Form("", 'POST', $inputs, '');
  599. }
  600. if ($type == 'INT') {
  601. $inputs .= wf_TextInput(self::PROUTE_MODCONTENT, '', $currentFieldContent, false, 10, 'digits');
  602. $inputs .= wf_Submit(__('Save'));
  603. $result = wf_Form("", 'POST', $inputs, '');
  604. }
  605. if ($type == 'FLOAT') {
  606. $inputs .= wf_TextInput(self::PROUTE_MODCONTENT, '', $currentFieldContent, false, 10, 'float');
  607. $inputs .= wf_Submit(__('Save'));
  608. $result = wf_Form("", 'POST', $inputs, '');
  609. }
  610. if ($type == 'FINANCE') {
  611. $inputs .= wf_TextInput(self::PROUTE_MODCONTENT, '', $currentFieldContent, false, 10, 'float');
  612. $inputs .= wf_Submit(__('Save'));
  613. $result = wf_Form("", 'POST', $inputs, '');
  614. }
  615. if ($type == 'NETWORK') {
  616. $inputs .= wf_TextInput(self::PROUTE_MODCONTENT, '', $currentFieldContent, false, 10, 'net-cidr');
  617. $inputs .= wf_Submit(__('Save'));
  618. $result = wf_Form("", 'POST', $inputs, '');
  619. }
  620. if ($type == 'URL') {
  621. $inputs .= wf_TextInput(self::PROUTE_MODCONTENT, '', $currentFieldContent, false, 20, 'url');
  622. $inputs .= wf_Submit(__('Save'));
  623. $result = wf_Form("", 'POST', $inputs, '');
  624. }
  625. if ($type == 'DATE') {
  626. $inputs .= wf_DatePickerPreset(self::PROUTE_MODCONTENT, $currentFieldContent, true) . ' ';
  627. $inputs .= wf_Submit(__('Save'));
  628. $result = wf_Form("", 'POST', $inputs, '');
  629. }
  630. if ($type == 'TIME') {
  631. $inputs .= wf_TimePickerPreset(self::PROUTE_MODCONTENT, $currentFieldContent, '', false) . ' ';
  632. $inputs .= wf_Submit(__('Save'));
  633. $result = wf_Form("", 'POST', $inputs, '');
  634. }
  635. if ($type == 'COLOR') {
  636. $inputs .= wf_ColPicker(self::PROUTE_MODCONTENT, '', $currentFieldContent, false, 10);
  637. $inputs .= wf_Submit(__('Save'));
  638. $result = wf_Form("", 'POST', $inputs, '');
  639. }
  640. if ($type == 'LIST') {
  641. if (isset($this->allTypes[$typeId])) {
  642. $typeName = $this->allTypes[$typeId]['name'];
  643. if (ispos($typeName, '[') AND ispos($typeName, ']')) {
  644. $rawList = zb_ParseTagData('[', ']', $typeName);
  645. if (!empty($rawList)) {
  646. $selectorOpts = array();
  647. $rawList = explode(',', $rawList);
  648. if (!empty($rawList)) {
  649. $selectorOpts[''] = '-';
  650. foreach ($rawList as $io => $each) {
  651. $cleanOpt = trim($each);
  652. $selectorOpts[$cleanOpt] = $cleanOpt;
  653. }
  654. }
  655. $inputs .= wf_Selector(self::PROUTE_MODCONTENT, $selectorOpts, '', $currentFieldContent, false);
  656. $inputs .= wf_Submit(__('Save'));
  657. $result = wf_Form("", 'POST', $inputs, '');
  658. } else {
  659. $result .= __('Wrong element format') . ': ' . __('is empty');
  660. }
  661. } else {
  662. $result .= __('Wrong element format') . ': ' . __('No tags');
  663. }
  664. }
  665. }
  666. if ($type == 'PHOTO') {
  667. if ($this->altCfg['PHOTOSTORAGE_ENABLED']) {
  668. $uploadUrl = self::URL_PHOTOUPL . $login . self::PHOTOSTORAGE_ITEMID_DELIMITER . $typeId;
  669. $result = wf_Link($uploadUrl, wf_img('skins/photostorage.png', __('Upload images')) . ' ' . __('Upload images'));
  670. } else {
  671. $result = __('Disabled');
  672. }
  673. }
  674. if ($type == 'FILE') {
  675. if ($this->altCfg['FILESTORAGE_ENABLED']) {
  676. $fileStorageItemId = $login . self::FILESTORAGE_ITEMID_DELIMITER . $typeId;
  677. $uploadUrl = self::URL_FILEUPL . $fileStorageItemId;
  678. $result = wf_Link($uploadUrl, wf_img('skins/photostorage_upload.png') . ' ' . __('Upload files'), false);
  679. } else {
  680. $result = __('Disabled');
  681. }
  682. }
  683. return ($result);
  684. }
  685. /**
  686. * Returns search controller for CFs assigned to user
  687. *
  688. * @param string $type Type of CF to return control
  689. * @param int $typeid Type ID for change
  690. *
  691. * @return string
  692. */
  693. function getTypeSearchControl($type, $typeid) {
  694. $type = ubRouting::filters($type, 'vf');
  695. $typeid = ubRouting::filters($typeid, 'int');
  696. $result = '';
  697. $inputs = '';
  698. $ignoredTypes = array('PHOTO', 'FILE', 'COLOR'); //I`m too lazy to do it today
  699. $ignoredTypes = array_flip($ignoredTypes);
  700. if (!isset($ignoredTypes[$type])) {
  701. if ($type == 'VARCHAR') {
  702. $inputs = wf_HiddenInput(self::PROUTE_SEARCHTYPEID, $typeid);
  703. $inputs .= wf_TextInput(self::PROUTE_SEARCHQUERY, '', '', false, 20);
  704. }
  705. if ($type == 'TRIGGER') {
  706. $triggerOpts = array(1 => __('Yes'), 0 => __('No'));
  707. $inputs = wf_HiddenInput(self::PROUTE_SEARCHTYPEID, $typeid);
  708. $inputs .= wf_Selector(self::PROUTE_SEARCHQUERY, $triggerOpts, '', '', false);
  709. }
  710. if ($type == 'TEXT') {
  711. $inputs = wf_HiddenInput(self::PROUTE_SEARCHTYPEID, $typeid);
  712. $inputs .= wf_TextInput(self::PROUTE_SEARCHQUERY, '', '', false, 20);
  713. }
  714. if ($type == 'INT') {
  715. $inputs = wf_HiddenInput(self::PROUTE_SEARCHTYPEID, $typeid);
  716. $inputs .= wf_TextInput(self::PROUTE_SEARCHQUERY, '', '', false, 10, 'digits');
  717. }
  718. if ($type == 'FLOAT') {
  719. $inputs = wf_HiddenInput(self::PROUTE_SEARCHTYPEID, $typeid);
  720. $inputs .= wf_TextInput(self::PROUTE_SEARCHQUERY, '', '', false, 10, 'float');
  721. }
  722. if ($type == 'FINANCE') {
  723. $inputs = wf_HiddenInput(self::PROUTE_SEARCHTYPEID, $typeid);
  724. $inputs .= wf_TextInput(self::PROUTE_SEARCHQUERY, '', '', false, 10, 'finance');
  725. }
  726. if ($type == 'NETWORK') {
  727. $inputs = wf_HiddenInput(self::PROUTE_SEARCHTYPEID, $typeid);
  728. $inputs .= wf_TextInput(self::PROUTE_SEARCHQUERY, '', '', false, 10, 'net-cidr');
  729. }
  730. if ($type == 'URL') {
  731. $inputs = wf_HiddenInput(self::PROUTE_SEARCHTYPEID, $typeid);
  732. $inputs .= wf_TextInput(self::PROUTE_SEARCHQUERY, '', '', false, 20, 'url');
  733. }
  734. if ($type == 'DATE') {
  735. $inputs = wf_HiddenInput(self::PROUTE_SEARCHTYPEID, $typeid) . ' ';
  736. $inputs .= wf_DatePicker(self::PROUTE_SEARCHQUERY, true);
  737. }
  738. if ($type == 'TIME') {
  739. $inputs = wf_HiddenInput(self::PROUTE_SEARCHTYPEID, $typeid);
  740. $inputs .= wf_TimePickerPreset(self::PROUTE_SEARCHQUERY, '', '', false) . ' ';
  741. }
  742. if ($type == 'LIST') {
  743. $inputs = wf_HiddenInput(self::PROUTE_SEARCHTYPEID, $typeid);
  744. if (isset($this->allTypes[$typeid])) {
  745. $typeName = $this->allTypes[$typeid]['name'];
  746. if (ispos($typeName, '[') AND ispos($typeName, ']')) {
  747. $rawList = zb_ParseTagData('[', ']', $typeName);
  748. if (!empty($rawList)) {
  749. $selectorOpts = array();
  750. $rawList = explode(',', $rawList);
  751. if (!empty($rawList)) {
  752. $selectorOpts[''] = '-';
  753. foreach ($rawList as $io => $each) {
  754. $cleanOpt = trim($each);
  755. $selectorOpts[$cleanOpt] = $cleanOpt;
  756. }
  757. $inputs .= wf_Selector(self::PROUTE_SEARCHQUERY, $selectorOpts, '', '', false);
  758. }
  759. }
  760. }
  761. }
  762. }
  763. }
  764. if (!empty($inputs)) {
  765. $inputs .= wf_Submit(__('Search')); //appending search button to each
  766. $result = wf_Form("", 'POST', $inputs, '');
  767. }
  768. return ($result);
  769. }
  770. }