Cheetah
ChEventsFormAdd.php
Go to the documentation of this file.
1 <?php
2 
8 ch_import ('ChWsbProfileFields');
9 ch_import ('ChWsbFormMedia');
10 
12 {
13  var $_oMain, $_oDb;
14 
15  function __construct ($oMain, $iProfileId, $iEntryId = 0, $iThumb = 0)
16  {
17  $this->_oMain = $oMain;
18  $this->_oDb = $oMain->_oDb;
19 
20  $this->_aMedia = array ();
21 
22  if (ChWsbRequest::serviceExists('photos', 'perform_photo_upload', 'Uploader'))
23  $this->_aMedia['images'] = array (
24  'post' => 'ready_images',
25  'upload_func' => 'uploadPhotos',
26  'tag' => CH_EVENTS_PHOTOS_TAG,
27  'cat' => CH_EVENTS_PHOTOS_CAT,
28  'thumb' => 'PrimPhoto',
29  'module' => 'photos',
30  'title_upload_post' => 'images_titles',
31  'title_upload' => _t('_ch_events_form_caption_file_title'),
32  'service_method' => 'get_photo_array',
33  );
34 
35  if (ChWsbRequest::serviceExists('videos', 'perform_video_upload', 'Uploader'))
36  $this->_aMedia['videos'] = array (
37  'post' => 'ready_videos',
38  'upload_func' => 'uploadVideos',
39  'tag' => CH_EVENTS_VIDEOS_TAG,
40  'cat' => CH_EVENTS_VIDEOS_CAT,
41  'thumb' => false,
42  'module' => 'videos',
43  'title_upload_post' => 'videos_titles',
44  'title_upload' => _t('_ch_events_form_caption_file_title'),
45  'service_method' => 'get_video_array',
46  );
47 
48  if (ChWsbRequest::serviceExists('sounds', 'perform_music_upload', 'Uploader'))
49  $this->_aMedia['sounds'] = array (
50  'post' => 'ready_sounds',
51  'upload_func' => 'uploadSounds',
52  'tag' => CH_EVENTS_SOUNDS_TAG,
53  'cat' => CH_EVENTS_SOUNDS_CAT,
54  'thumb' => false,
55  'module' => 'sounds',
56  'title_upload_post' => 'sounds_titles',
57  'title_upload' => _t('_ch_events_form_caption_file_title'),
58  'service_method' => 'get_music_array',
59  );
60 
61  if (ChWsbRequest::serviceExists('files', 'perform_file_upload', 'Uploader'))
62  $this->_aMedia['files'] = array (
63  'post' => 'ready_files',
64  'upload_func' => 'uploadFiles',
65  'tag' => CH_EVENTS_FILES_TAG,
66  'cat' => CH_EVENTS_FILES_CAT,
67  'thumb' => false,
68  'module' => 'files',
69  'title_upload_post' => 'files_titles',
70  'title_upload' => _t('_ch_events_form_caption_file_title'),
71  'service_method' => 'get_file_array',
72  );
73 
74  ch_import('ChWsbCategories');
75  $oCategories = new ChWsbCategories();
76  $oCategories->getTagObjectConfig ();
77 
78  $oProfileFields = new ChWsbProfileFields(0);
79  $aCountries = $oProfileFields->convertValues4Input('#!Country');
80 
81  // generate templates for form custom elements
82  $aCustomMediaTemplates = $this->generateCustomMediaTemplates ($this->_oMain->_iProfileId, $iEntryId, $iThumb);
83 
84  // privacy
85 
86  $aInputPrivacyCustom = array ();
87  $aInputPrivacyCustom[] = array ('key' => '', 'value' => '----');
88  $aInputPrivacyCustom[] = array ('key' => 'p', 'value' => _t('_ch_events_privacy_participants_only'));
89  $aInputPrivacyCustomPass = array (
90  'pass' => 'Preg',
91  'params' => array('/^([0-9p]+)$/'),
92  );
93 
94  $aInputPrivacyCustom2 = array (
95  array('key' => 'p', 'value' => _t('_ch_events_privacy_participants')),
96  array('key' => 'a', 'value' => _t('_ch_events_privacy_admins_only'))
97  );
98  $aInputPrivacyCustom2Pass = array (
99  'pass' => 'Preg',
100  'params' => array('/^([pa]+)$/'),
101  );
102 
103  $aInputPrivacyViewParticipants = $GLOBALS['oChEventsModule']->_oPrivacy->getGroupChooser($iProfileId, 'events', 'view_participants');
104  $aInputPrivacyViewParticipants['values'] = array_merge($aInputPrivacyViewParticipants['values'], $aInputPrivacyCustom);
105 
106  $aInputPrivacyComment = $GLOBALS['oChEventsModule']->_oPrivacy->getGroupChooser($iProfileId, 'events', 'comment');
107  $aInputPrivacyComment['values'] = array_merge($aInputPrivacyComment['values'], $aInputPrivacyCustom);
108  $aInputPrivacyComment['db'] = $aInputPrivacyCustomPass;
109 
110  $aInputPrivacyRate = $GLOBALS['oChEventsModule']->_oPrivacy->getGroupChooser($iProfileId, 'events', 'rate');
111  $aInputPrivacyRate['values'] = array_merge($aInputPrivacyRate['values'], $aInputPrivacyCustom);
112  $aInputPrivacyRate['db'] = $aInputPrivacyCustomPass;
113 
114  $aInputPrivacyForum = $GLOBALS['oChEventsModule']->_oPrivacy->getGroupChooser($iProfileId, 'events', 'post_in_forum');
115  $aInputPrivacyForum['values'] = array_merge($aInputPrivacyForum['values'], $aInputPrivacyCustom);
116  $aInputPrivacyForum['db'] = $aInputPrivacyCustomPass;
117 
118  $aInputPrivacyForumView = $GLOBALS['oChEventsModule']->_oPrivacy->getGroupChooser($iProfileId, 'events', 'view_forum');
119  $aInputPrivacyForumView['values'] = array_merge($aInputPrivacyForumView['values'], $aInputPrivacyCustom);
120  $aInputPrivacyForumView['db'] = $aInputPrivacyCustomPass;
121 
122  $aInputPrivacyUploadPhotos = $this->_oMain->_oPrivacy->getGroupChooser($iProfileId, 'events', 'upload_photos');
123  $aInputPrivacyUploadPhotos['values'] = $aInputPrivacyCustom2;
124  $aInputPrivacyUploadPhotos['db'] = $aInputPrivacyCustom2Pass;
125 
126  $aInputPrivacyUploadVideos = $this->_oMain->_oPrivacy->getGroupChooser($iProfileId, 'events', 'upload_videos');
127  $aInputPrivacyUploadVideos['values'] = $aInputPrivacyCustom2;
128  $aInputPrivacyUploadVideos['db'] = $aInputPrivacyCustom2Pass;
129 
130  $aInputPrivacyUploadSounds = $this->_oMain->_oPrivacy->getGroupChooser($iProfileId, 'events', 'upload_sounds');
131  $aInputPrivacyUploadSounds['values'] = $aInputPrivacyCustom2;
132  $aInputPrivacyUploadSounds['db'] = $aInputPrivacyCustom2Pass;
133 
134  $aInputPrivacyUploadFiles = $this->_oMain->_oPrivacy->getGroupChooser($iProfileId, 'events', 'upload_files');
135  $aInputPrivacyUploadFiles['values'] = $aInputPrivacyCustom2;
136  $aInputPrivacyUploadFiles['db'] = $aInputPrivacyCustom2Pass;
137 
138  $aCustomForm = array(
139 
140  'form_attrs' => array(
141  'name' => 'form_events',
142  'action' => '',
143  'method' => 'post',
144  'enctype' => 'multipart/form-data',
145  ),
146 
147  'params' => array (
148  'db' => array(
149  'table' => 'ch_events_main',
150  'key' => 'ID',
151  'uri' => 'EntryUri',
152  'uri_title' => 'Title',
153  'submit_name' => 'submit_form',
154  ),
155  ),
156 
157  'inputs' => array(
158 
159  'header_info' => array(
160  'type' => 'block_header',
161  'caption' => _t('_ch_events_form_header_info')
162  ),
163 
164  'Title' => array(
165  'type' => 'text',
166  'name' => 'Title',
167  'caption' => _t('_ch_events_caption_title'),
168  'required' => true,
169  'checker' => array (
170  'func' => 'length',
171  'params' => array(3,100),
172  'error' => _t ('_ch_events_err_title'),
173  ),
174  'db' => array (
175  'pass' => 'Xss',
176  ),
177  ),
178  'Description' => array(
179  'type' => 'textarea',
180  'name' => 'Description',
181  'caption' => _t('_ch_events_caption_desc'),
182  'required' => true,
183  'html' => 2,
184  'checker' => array (
185  'func' => 'length',
186  'params' => array(20,64000),
187  'error' => _t ('_ch_events_err_desc'),
188  ),
189  'db' => array (
190  'pass' => 'XssHtml',
191  ),
192  ),
193  'Country' => array(
194  'type' => 'select',
195  'name' => 'Country',
196  'caption' => _t('_ch_events_caption_country'),
197  'values' => $aCountries,
198  'required' => true,
199  'checker' => array (
200  'func' => 'preg',
201  'params' => array('/^[a-zA-Z]{2}$/'),
202  'error' => _t ('_ch_events_err_country'),
203  ),
204  'db' => array (
205  'pass' => 'Preg',
206  'params' => array('/([a-zA-Z]{2})/'),
207  ),
208  ),
209  'City' => array(
210  'type' => 'text',
211  'name' => 'City',
212  'caption' => _t('_ch_events_caption_city'),
213  'required' => true,
214  'checker' => array (
215  'func' => 'length',
216  'params' => array(3,50),
217  'error' => _t ('_ch_events_err_city'),
218  ),
219  'db' => array (
220  'pass' => 'Xss',
221  ),
222  ),
223  'Place' => array(
224  'type' => 'text',
225  'name' => 'Place',
226  'caption' => _t('_ch_events_caption_place'),
227  'required' => true,
228  'checker' => array (
229  'func' => 'avail',
230  'error' => _t ('_ch_events_err_place'),
231  ),
232  'db' => array (
233  'pass' => 'Xss',
234  ),
235  ),
236  'EventStart' => array(
237  'type' => 'datetime',
238  'name' => 'EventStart',
239  'caption' => _t('_ch_events_caption_event_start'),
240  'required' => true,
241  'checker' => array (
242  'func' => 'DateTime',
243  'error' => _t ('_ch_events_err_event_start'),
244  ),
245  'db' => array (
246  'pass' => 'DateTimeUTC',
247  ),
248  'display' => 'filterDateUTC',
249  ),
250  'EventEnd' => array(
251  'type' => 'datetime',
252  'name' => 'EventEnd',
253  'caption' => _t('_ch_events_caption_event_end'),
254  'required' => true,
255  'checker' => array (
256  'func' => 'DateTime',
257  'error' => _t ('_ch_events_err_event_end'),
258  ),
259  'db' => array (
260  'pass' => 'DateTimeUTC',
261  ),
262  'display' => 'filterDateUTC',
263  ),
264  'Tags' => array(
265  'type' => 'text',
266  'name' => 'Tags',
267  'caption' => _t('_Tags'),
268  'info' => _t('_sys_tags_note'),
269  'required' => true,
270  'checker' => array (
271  'func' => 'avail',
272  'error' => _t ('_ch_events_err_tags'),
273  ),
274  'db' => array (
275  'pass' => 'Tags',
276  ),
277  ),
278 
279  'Categories' => $oCategories->getGroupChooser ('ch_events', (int)$iProfileId, true),
280 
281  // images
282 
283  'header_images' => array(
284  'type' => 'block_header',
285  'caption' => _t('_ch_events_form_header_images'),
286  'collapsable' => true,
287  'collapsed' => false,
288  ),
289  'PrimPhoto' => array(
290  'type' => 'custom',
291  'content' => $aCustomMediaTemplates['images']['thumb_choice'],
292  'name' => 'PrimPhoto',
293  'caption' => _t('_ch_events_form_caption_thumb_choice'),
294  'info' => _t('_ch_events_form_info_thumb_choice'),
295  'required' => false,
296  'db' => array (
297  'pass' => 'Int',
298  ),
299  ),
300  'images_choice' => array(
301  'type' => 'custom',
302  'content' => $aCustomMediaTemplates['images']['choice'],
303  'name' => 'images_choice[]',
304  'caption' => _t('_ch_events_form_caption_images_choice'),
305  'info' => _t('_ch_events_form_info_images_choice'),
306  'required' => false,
307  ),
308  'images_upload' => array(
309  'type' => 'custom',
310  'content' => $aCustomMediaTemplates['images']['upload'],
311  'name' => 'images_upload[]',
312  'caption' => _t('_ch_events_form_caption_images_upload'),
313  'info' => _t('_ch_events_form_info_images_upload'),
314  'required' => false,
315  ),
316 
317  // videos
318 
319  'header_videos' => array(
320  'type' => 'block_header',
321  'caption' => _t('_ch_events_form_header_videos'),
322  'collapsable' => true,
323  'collapsed' => false,
324  ),
325  'videos_choice' => array(
326  'type' => 'custom',
327  'content' => $aCustomMediaTemplates['videos']['choice'],
328  'name' => 'videos_choice[]',
329  'caption' => _t('_ch_events_form_caption_videos_choice'),
330  'info' => _t('_ch_events_form_info_videos_choice'),
331  'required' => false,
332  ),
333  'videos_upload' => array(
334  'type' => 'custom',
335  'content' => $aCustomMediaTemplates['videos']['upload'],
336  'name' => 'videos_upload[]',
337  'caption' => _t('_ch_events_form_caption_videos_upload'),
338  'info' => _t('_ch_events_form_info_videos_upload'),
339  'required' => false,
340  ),
341 
342  // sounds
343 
344  'header_sounds' => array(
345  'type' => 'block_header',
346  'caption' => _t('_ch_events_form_header_sounds'),
347  'collapsable' => true,
348  'collapsed' => false,
349  ),
350  'sounds_choice' => array(
351  'type' => 'custom',
352  'content' => $aCustomMediaTemplates['sounds']['choice'],
353  'name' => 'sounds_choice[]',
354  'caption' => _t('_ch_events_form_caption_sounds_choice'),
355  'info' => _t('_ch_events_form_info_sounds_choice'),
356  'required' => false,
357  ),
358  'sounds_upload' => array(
359  'type' => 'custom',
360  'content' => $aCustomMediaTemplates['sounds']['upload'],
361  'name' => 'sounds_upload[]',
362  'caption' => _t('_ch_events_form_caption_sounds_upload'),
363  'info' => _t('_ch_events_form_info_sounds_upload'),
364  'required' => false,
365  ),
366 
367  // files
368 
369  'header_files' => array(
370  'type' => 'block_header',
371  'caption' => _t('_ch_events_form_header_files'),
372  'collapsable' => true,
373  'collapsed' => false,
374  ),
375  'files_choice' => array(
376  'type' => 'custom',
377  'content' => $aCustomMediaTemplates['files']['choice'],
378  'name' => 'files_choice[]',
379  'caption' => _t('_ch_events_form_caption_files_choice'),
380  'info' => _t('_ch_events_form_info_files_choice'),
381  'required' => false,
382  ),
383  'files_upload' => array(
384  'type' => 'custom',
385  'content' => $aCustomMediaTemplates['files']['upload'],
386  'name' => 'files_upload[]',
387  'caption' => _t('_ch_events_form_caption_files_upload'),
388  'info' => _t('_ch_events_form_info_files_upload'),
389  'required' => false,
390  ),
391 
392  // privacy
393 
394  'header_privacy' => array(
395  'type' => 'block_header',
396  'caption' => _t('_ch_events_form_header_privacy'),
397  ),
398 
399  'allow_view_event_to' => $GLOBALS['oChEventsModule']->_oPrivacy->getGroupChooser($iProfileId, 'events', 'view_event'),
400 
401  'allow_view_participants_to' => $aInputPrivacyViewParticipants,
402 
403  'allow_comment_to' => $aInputPrivacyComment,
404 
405  'allow_rate_to' => $aInputPrivacyRate,
406 
407  'allow_post_in_forum_to' => $aInputPrivacyForum,
408 
409  'allow_view_forum_to' => $aInputPrivacyForumView,
410 
411  'allow_join_to' => $GLOBALS['oChEventsModule']->_oPrivacy->getGroupChooser($iProfileId, 'events', 'join'),
412 
413  'JoinConfirmation' => array (
414  'type' => 'select',
415  'name' => 'JoinConfirmation',
416  'caption' => _t('_ch_events_form_caption_join_confirmation'),
417  'info' => _t('_ch_events_form_info_join_confirmation'),
418  'values' => array(
419  0 => _t('_ch_events_form_join_confirmation_disabled'),
420  1 => _t('_ch_events_form_join_confirmation_enabled'),
421  ),
422  'checker' => array (
423  'func' => 'int',
424  'error' => _t ('_ch_events_form_err_join_confirmation'),
425  ),
426  'db' => array (
427  'pass' => 'Int',
428  ),
429  ),
430 
431  'allow_upload_photos_to' => $aInputPrivacyUploadPhotos,
432 
433  'allow_upload_videos_to' => $aInputPrivacyUploadVideos,
434 
435  'allow_upload_sounds_to' => $aInputPrivacyUploadSounds,
436 
437  'allow_upload_files_to' => $aInputPrivacyUploadFiles,
438  ),
439  );
440 
441  if (!$aCustomForm['inputs']['images_choice']['content']) {
442  unset ($aCustomForm['inputs']['PrimPhoto']);
443  unset ($aCustomForm['inputs']['images_choice']);
444  }
445 
446  if (!$aCustomForm['inputs']['videos_choice']['content'])
447  unset ($aCustomForm['inputs']['videos_choice']);
448 
449  if (!$aCustomForm['inputs']['sounds_choice']['content'])
450  unset ($aCustomForm['inputs']['sounds_choice']);
451 
452  if (!$aCustomForm['inputs']['files_choice']['content'])
453  unset ($aCustomForm['inputs']['files_choice']);
454 
455  if (!isset($this->_aMedia['images'])) {
456  unset ($aCustomForm['inputs']['header_images']);
457  unset ($aCustomForm['inputs']['PrimPhoto']);
458  unset ($aCustomForm['inputs']['images_choice']);
459  unset ($aCustomForm['inputs']['images_upload']);
460  unset ($aCustomForm['inputs']['allow_upload_photos_to']);
461  }
462 
463  if (!isset($this->_aMedia['videos'])) {
464  unset ($aCustomForm['inputs']['header_videos']);
465  unset ($aCustomForm['inputs']['videos_choice']);
466  unset ($aCustomForm['inputs']['videos_upload']);
467  unset ($aCustomForm['inputs']['allow_upload_videos_to']);
468  }
469 
470  if (!isset($this->_aMedia['sounds'])) {
471  unset ($aCustomForm['inputs']['header_sounds']);
472  unset ($aCustomForm['inputs']['sounds_choice']);
473  unset ($aCustomForm['inputs']['sounds_upload']);
474  unset ($aCustomForm['inputs']['allow_upload_sounds_to']);
475  }
476 
477  if (!isset($this->_aMedia['files'])) {
478  unset ($aCustomForm['inputs']['header_files']);
479  unset ($aCustomForm['inputs']['files_choice']);
480  unset ($aCustomForm['inputs']['files_upload']);
481  unset ($aCustomForm['inputs']['allow_upload_files_to']);
482  }
483 
484  $oModuleDb = new ChWsbModuleDb();
485  if (!$oModuleDb->getModuleByUri('forum'))
486  unset ($aCustomForm['inputs']['allow_post_in_forum_to']);
487 
488  $aFormInputsAdminPart = array ();
489  if ($GLOBALS['oChEventsModule']->isAdmin()) {
490 
491  require_once(CH_DIRECTORY_PATH_INC . 'membership_levels.inc.php');
492  $aMemberships = getMemberships ();
493  unset ($aMemberships[MEMBERSHIP_ID_NON_MEMBER]); // unset Non-member
494  $aMemberships = array('' => _t('_ch_events_membership_filter_none')) + $aMemberships;
495  $aFormInputsAdminPart = array (
496  'EventMembershipFilter' => array(
497  'type' => 'select',
498  'name' => 'EventMembershipFilter',
499  'caption' => _t('_ch_events_caption_membership_filter'),
500  'info' => _t('_ch_events_info_membership_filter'),
501  'values' => $aMemberships,
502  'value' => '',
503  'checker' => array (
504  'func' => 'preg',
505  'params' => array('/^[0-9a-zA-Z]*$/'),
506  'error' => _t ('_ch_events_err_membership_filter'),
507  ),
508  'db' => array (
509  'pass' => 'Preg',
510  'params' => array('/([0-9a-zA-Z]*)/'),
511  ),
512 
513  ),
514  );
515  }
516 
517  $aFormInputsSubmit = array (
518  'Submit' => array (
519  'type' => 'submit',
520  'name' => 'submit_form',
521  'value' => _t('_Submit'),
522  ),
523  );
524 
525  $aCustomForm['inputs'] = array_merge($aCustomForm['inputs'], $aFormInputsAdminPart, $aFormInputsSubmit);
526 
527  $this->processMembershipChecksForMediaUploads ($aCustomForm['inputs']);
528 
529  parent::__construct ($aCustomForm);
530  }
531 
532 }
CH_EVENTS_PHOTOS_TAG
const CH_EVENTS_PHOTOS_TAG
Definition: ChEventsModule.php:24
ChWsbProfileFields
Definition: ChWsbProfileFields.php:13
ChEventsFormAdd\$_oDb
$_oDb
Definition: ChEventsFormAdd.php:13
CH_EVENTS_SOUNDS_CAT
const CH_EVENTS_SOUNDS_CAT
Definition: ChEventsModule.php:29
CH_EVENTS_VIDEOS_CAT
const CH_EVENTS_VIDEOS_CAT
Definition: ChEventsModule.php:26
ChWsbRequest\serviceExists
static serviceExists($mixedModule, $sMethod, $sClass="Module")
Definition: ChWsbRequest.php:70
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
php
ChWsbModuleDb
Definition: ChWsbModuleDb.php:12
CH_EVENTS_VIDEOS_TAG
const CH_EVENTS_VIDEOS_TAG
Definition: ChEventsModule.php:27
ChEventsFormAdd\$_oMain
$_oMain
Definition: ChEventsFormAdd.php:13
getMemberships
getMemberships($purchasableOnly=false)
Definition: membership_levels.inc.php:670
ChWsbCategories
Definition: ChWsbCategories.php:13
CH_EVENTS_PHOTOS_CAT
const CH_EVENTS_PHOTOS_CAT
Definition: ChEventsModule.php:23
isAdmin
isAdmin()
Definition: index.php:649
ChWsbFormMedia
Definition: ChWsbFormMedia.php:14
$oModuleDb
$oModuleDb
Definition: classifieds.php:20
CH_EVENTS_SOUNDS_TAG
const CH_EVENTS_SOUNDS_TAG
Definition: ChEventsModule.php:30
ChEventsFormAdd\__construct
__construct($oMain, $iProfileId, $iEntryId=0, $iThumb=0)
Definition: ChEventsFormAdd.php:15
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
MEMBERSHIP_ID_NON_MEMBER
const MEMBERSHIP_ID_NON_MEMBER
Definition: membership_levels.inc.php:48
ChEventsFormAdd
Definition: ChEventsFormAdd.php:12
ChWsbFormMedia\processMembershipChecksForMediaUploads
processMembershipChecksForMediaUploads(&$aInputs)
Definition: ChWsbFormMedia.php:366
CH_EVENTS_FILES_TAG
const CH_EVENTS_FILES_TAG
Definition: ChEventsModule.php:33
CH_EVENTS_FILES_CAT
const CH_EVENTS_FILES_CAT
Definition: ChEventsModule.php:32
ChWsbFormMedia\generateCustomMediaTemplates
generateCustomMediaTemplates($iProfileId, $iEntryId, $iThumb=0)
Definition: ChWsbFormMedia.php:316
$iProfileId
if( $sMembersList) $iProfileId
Definition: communicator.php:29
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10