Cheetah
ChStoreFormAdd.php
Go to the documentation of this file.
1 <?php
2 
8 ch_import('ChWsbProfileFields');
9 ch_import('ChWsbFormMedia');
10 
12 {
13  var $_oMain;
14  var $_oDb;
15 
16  function __construct ($oMain, $iProfileId, $isRemovePhotoFieldAllowed = true, $iEntryId = 0, $iThumb = 0)
17  {
18  $this->_aMedia = array ();
19  if (ChWsbRequest::serviceExists('photos', 'perform_photo_upload', 'Uploader'))
20  $this->_aMedia['images'] = array (
21  'post' => 'ready_images',
22  'upload_func' => 'uploadPhotos',
23  'tag' => CH_STORE_PHOTOS_TAG,
24  'cat' => CH_STORE_PHOTOS_CAT,
25  'thumb' => 'thumb',
26  'module' => 'photos',
27  'title_upload_post' => 'images_titles',
28  'title_upload' => _t('_ch_store_form_caption_file_title'),
29  'service_method' => 'get_photo_array',
30  );
31 
32  if (ChWsbRequest::serviceExists('videos', 'perform_video_upload', 'Uploader'))
33  $this->_aMedia['videos'] = array (
34  'post' => 'ready_videos',
35  'upload_func' => 'uploadVideos',
36  'tag' => CH_STORE_VIDEOS_TAG,
37  'cat' => CH_STORE_VIDEOS_CAT,
38  'thumb' => false,
39  'module' => 'videos',
40  'title_upload' => _t('_ch_store_form_caption_file_title'),
41  'service_method' => 'get_video_array',
42  );
43 
44  $this->_oMain = $oMain;
45  $this->_oDb = $oMain->_oDb;
46 
47  ch_import('ChWsbCategories');
48  $oCategories = new ChWsbCategories();
49  $oCategories->getTagObjectConfig ();
50 
51  // generate templates for form custom elements
52 
53  $aCustomMediaTemplates = $this->generateCustomMediaTemplates ($iProfileId, $iEntryId, $iThumb);
54 
55  // files
56 
57  $aFilesChoiceOrig = $this->_getFilesInEntry ('files', 'get_file_array', 'ready_files', 'files', (int)$iProfileId, $iEntryId);
58  $aFilesChoice = array ();
59  $sCurrencySign = getParam('pmt_default_currency_sign');
60  foreach ($aFilesChoiceOrig as $k => $r) {
61  if (!$r['checked']) continue;
62  $a = $GLOBALS['oChStoreModule']->_oDb->getFileInfo ($iEntryId, $r['id']);
63  $r['file_id'] = $a['id'];
64  $r['title'] .= ' - ' . $sCurrencySign . ' ' . $a['price'] . ' (' . $GLOBALS['oChStoreModule']->getGroupName($a['allow_purchase_to']) . ')';
65  $r['visibility'] = $a['hidden'] ? _t('_ch_store_product_file_hidden') : _t('_ch_store_product_file_visible');
66  $aFilesChoice[] = $r;
67  }
68  $aVarsFilesChoice = array(
69  'ch_store_base_url' => $this->_oMain->_oConfig->getBaseUri(),
70  'ch_if:empty' => array(
71  'condition' => empty($aFilesChoice),
72  'content' => array ()
73  ),
74  'ch_repeat:files' => $aFilesChoice,
75  );
76 
77  $aInputPrivacyPurchase = $GLOBALS['oChStoreModule']->_oPrivacyProduct->getGroupChooser($iProfileId, 'store', 'purchase');
78  foreach ($aInputPrivacyPurchase['values'] as $k => $r) {
79  if ($r['key'] == CH_WSB_PG_ALL) {
80  unset ($aInputPrivacyPurchase['values'][$k]);
81  break;
82  }
83  }
84 
85  require_once(CH_DIRECTORY_PATH_INC . 'membership_levels.inc.php');
86  $aMemberships = getMemberships ();
87  unset ($aMemberships[MEMBERSHIP_ID_NON_MEMBER]); // unset Non-member
88  unset ($aMemberships[MEMBERSHIP_ID_STANDARD]); // unset member
89 
90  $aMemberships = array('' => '----') + $aMemberships;
91  $aMembershipsValues = array ();
92  foreach ($aMemberships as $k => $v)
93  $aMembershipsValues[] = array ('key' => $k ? 'm' . $k : $k, 'value' => $v);
94  $aInputPrivacyPurchase['values'] = array_merge($aInputPrivacyPurchase['values'], $aMembershipsValues);
95 /*
96  if (empty($aInputPrivacyPurchase['value']) || !$aInputPrivacyPurchase['value'])
97  $aInputPrivacyPurchase['value'] = CH_WSB_PG_MEMBERS;
98  */
99  $sInputPrivacyPurchase = str_replace('name="allow_purchase_to"', 'name="allow_purchase_to[]"', $this->genInputSelect($aInputPrivacyPurchase));
100 
101  $aVarsFilesUpload = array (
102  'file' => 'files',
103  'title' => 'files_titles',
104  'file_upload_title' => _t('_ch_store_form_caption_file_title'),
105  'ch_if:price' => array (
106  'condition' => true, 'content' => array('price' => 'files_prices', 'file_price_title' => _t('_ch_store_form_caption_file_price'))
107  ),
108  'ch_if:privacy' => array (
109  'condition' => true, 'content' => array('select' => $sInputPrivacyPurchase, 'file_permission_title' => _t('_ch_store_form_caption_file_allow_purcase_to'))
110  ),
111  );
112 
113  // privacy
114 
115  $aInputPrivacyCustom = array ();
116  $aInputPrivacyCustom[] = array ('key' => '', 'value' => '----');
117  $aInputPrivacyCustom[] = array ('key' => 'c', 'value' => _t('_ch_store_privacy_customers_only'));
118 
119  $aInputPrivacyPostInForum = $GLOBALS['oChStoreModule']->_oPrivacyProduct->getGroupChooser($iProfileId, 'store', 'post_in_forum');
120  $aInputPrivacyPostInForum['values'] = array_merge($aInputPrivacyPostInForum['values'], $aInputPrivacyCustom);
121  $aInputPrivacyPostInForum['db'] = array (
122  'pass' => 'Preg',
123  'params' => array('/^([0-9c]+)$/'),
124  );
125 
126  $aInputPrivacyViewForum = $GLOBALS['oChStoreModule']->_oPrivacyProduct->getGroupChooser($iProfileId, 'store', 'view_forum');
127  $aInputPrivacyViewForum['values'] = array_merge($aInputPrivacyViewForum['values'], $aInputPrivacyCustom);
128  $aInputPrivacyViewForum['db'] = $aInputPrivacyPostInForum['db'];
129 
130  $aCustomForm = array(
131 
132  'form_attrs' => array(
133  'name' => 'form_store',
134  'action' => '',
135  'method' => 'post',
136  'enctype' => 'multipart/form-data',
137  ),
138 
139  'params' => array (
140  'db' => array(
141  'table' => 'ch_store_products',
142  'key' => 'id',
143  'uri' => 'uri',
144  'uri_title' => 'title',
145  'submit_name' => 'submit_form',
146  ),
147  ),
148 
149  'inputs' => array(
150 
151  'header_info' => array(
152  'type' => 'block_header',
153  'caption' => _t('_ch_store_form_header_info')
154  ),
155  'title' => array(
156  'type' => 'text',
157  'name' => 'title',
158  'caption' => _t('_ch_store_form_caption_title'),
159  'required' => true,
160  'checker' => array (
161  'func' => 'length',
162  'params' => array(3,100),
163  'error' => _t ('_ch_store_form_err_title'),
164  ),
165  'db' => array (
166  'pass' => 'Xss',
167  ),
168  ),
169  'desc' => array(
170  'type' => 'textarea',
171  'name' => 'desc',
172  'caption' => _t('_ch_store_form_caption_desc'),
173  'required' => true,
174  'html' => 2,
175  'checker' => array (
176  'func' => 'length',
177  'params' => array(20,64000),
178  'error' => _t ('_ch_store_form_err_desc'),
179  ),
180  'db' => array (
181  'pass' => 'XssHtml',
182  ),
183  ),
184  'tags' => array(
185  'type' => 'text',
186  'name' => 'tags',
187  'caption' => _t('_Tags'),
188  'info' => _t('_sys_tags_note'),
189  'required' => true,
190  'checker' => array (
191  'func' => 'avail',
192  'error' => _t ('_ch_store_form_err_tags'),
193  ),
194  'db' => array (
195  'pass' => 'Tags',
196  ),
197  ),
198 
199  'categories' => $oCategories->getGroupChooser ('ch_store', (int)$iProfileId, true),
200 
201  'header_images' => array(
202  'type' => 'block_header',
203  'caption' => _t('_ch_store_form_header_images'),
204  'collapsable' => true,
205  'collapsed' => false,
206  ),
207  'thumb' => array(
208  'type' => 'custom',
209  'content' => $aCustomMediaTemplates['images']['thumb_choice'],
210  'name' => 'thumb',
211  'caption' => _t('_ch_store_form_caption_thumb_choice'),
212  'info' => _t('_ch_store_form_info_thumb_choice'),
213  'required' => false,
214  'db' => array (
215  'pass' => 'Int',
216  ),
217  ),
218  'images_choice' => array(
219  'type' => 'custom',
220  'content' => $aCustomMediaTemplates['images']['choice'],
221  'name' => 'images_choice[]',
222  'caption' => _t('_ch_store_form_caption_images_choice'),
223  'info' => _t('_ch_store_form_info_images_choice'),
224  'required' => false,
225  ),
226  'images_upload' => array(
227  'type' => 'custom',
228  'content' => $aCustomMediaTemplates['images']['upload'],
229  'name' => 'images_upload[]',
230  'caption' => _t('_ch_store_form_caption_images_upload'),
231  'info' => _t('_ch_store_form_info_images_upload'),
232  'required' => false,
233  ),
234 
235  'header_videos' => array(
236  'type' => 'block_header',
237  'caption' => _t('_ch_store_form_header_videos'),
238  'collapsable' => true,
239  'collapsed' => false,
240  ),
241  'videos_choice' => array(
242  'type' => 'custom',
243  'content' => $aCustomMediaTemplates['videos']['choice'],
244  'name' => 'videos_choice[]',
245  'caption' => _t('_ch_store_form_caption_videos_choice'),
246  'info' => _t('_ch_store_form_info_videos_choice'),
247  'required' => false,
248  ),
249  'videos_upload' => array(
250  'type' => 'custom',
251  'content' => $aCustomMediaTemplates['videos']['upload'],
252  'name' => 'videos_upload[]',
253  'caption' => _t('_ch_store_form_caption_videos_upload'),
254  'info' => _t('_ch_store_form_info_videos_upload'),
255  'required' => false,
256  ),
257 
258  'header_files' => array(
259  'type' => 'block_header',
260  'caption' => _t('_ch_store_form_header_files'),
261  'collapsable' => true,
262  'collapsed' => false,
263  ),
264  'files_choice' => array(
265  'type' => 'custom',
266  'content' => $aFilesChoice ? $GLOBALS['oChStoreModule']->_oTemplate->parseHtmlByName('form_field_product_files_choice', $aVarsFilesChoice) : '',
267  'name' => 'files_choice[]',
268  'caption' => _t('_ch_store_form_caption_files_choice'),
269  'info' => _t('_ch_store_form_info_files_choice'),
270  'required' => false,
271  ),
272  'files_upload' => array(
273  'type' => 'custom',
274  'content' => $GLOBALS['oChStoreModule']->_oTemplate->parseHtmlByName('form_field_files_upload', $aVarsFilesUpload),
275  'name' => 'files_upload[]',
276  'caption' => _t('_ch_store_form_caption_files_upload'),
277  'info' => _t('_ch_store_form_info_files_upload'),
278  'required' => false,
279  ),
280 
281  'header_privacy' => array(
282  'type' => 'block_header',
283  'caption' => _t('_ch_store_form_header_privacy'),
284  ),
285 
286  'allow_view_product_to' => $GLOBALS['oChStoreModule']->_oPrivacyProduct->getGroupChooser($iProfileId, 'store', 'view_product'),
287 
288  'allow_post_in_forum_to' => $aInputPrivacyPostInForum,
289 
290  'allow_view_forum_to' => $aInputPrivacyViewForum,
291 
292  ),
293  );
294 
295  if (!$aCustomForm['inputs']['images_choice']['content']) {
296  unset ($aCustomForm['inputs']['thumb']);
297  unset ($aCustomForm['inputs']['images_choice']);
298  }
299 
300  if (!$aCustomForm['inputs']['videos_choice']['content'])
301  unset ($aCustomForm['inputs']['videos_choice']);
302 
303  if (!$aFilesChoice)
304  unset ($aCustomForm['inputs']['files_choice']);
305 
306  if (!isset($this->_aMedia['images'])) {
307  unset ($aCustomForm['inputs']['header_images']);
308  unset ($aCustomForm['inputs']['PrimPhoto']);
309  unset ($aCustomForm['inputs']['images_choice']);
310  unset ($aCustomForm['inputs']['images_upload']);
311  unset ($aCustomForm['inputs']['allow_upload_photos_to']);
312  }
313 
314  if (!isset($this->_aMedia['videos'])) {
315  unset ($aCustomForm['inputs']['header_videos']);
316  unset ($aCustomForm['inputs']['videos_choice']);
317  unset ($aCustomForm['inputs']['videos_upload']);
318  unset ($aCustomForm['inputs']['allow_upload_videos_to']);
319  }
320 
321  $aFormInputsSubmit = array (
322  'Submit' => array (
323  'type' => 'submit',
324  'name' => 'submit_form',
325  'value' => _t('_Submit'),
326  ),
327  );
328 
329  $aCustomForm['inputs'] = array_merge($aCustomForm['inputs'], $aFormInputsSubmit);
330 
331  $this->processMembershipChecksForMediaUploads ($aCustomForm['inputs']);
332 
333  parent::__construct ($aCustomForm);
334  }
335 
336  function uploadFiles ($sTag, $sCat, $sName = 'files', $sTitle = 'files_titles', $sTitleAlt = 'title', $sPrivacy = 'allow_purchase_to')
337  {
338  if(empty($sTag))
339  $sTag = CH_STORE_FILES_TAG;
340 
341  if(empty($sCat))
342  $sCat = CH_STORE_FILES_CAT;
343 
344  $aTitles = $this->getCleanValue($sTitle);
345  $aPrivacy = $this->getCleanValue($sPrivacy);
346  $aPrices = $_POST['files_prices'];
347 
348  $aRet = array();
349  foreach ($_FILES[$sName]['tmp_name'] as $i => $sUploadedFile) {
350  $aFileInfo = array (
351  'medTitle' => is_array($aTitles) && isset($aTitles[$i]) && $aTitles[$i] ? stripslashes($aTitles[$i]) : stripslashes($this->getCleanValue($sTitleAlt)),
352  'medDesc' => is_array($aTitles) && isset($aTitles[$i]) && $aTitles[$i] ? stripslashes($aTitles[$i]) : stripslashes($this->getCleanValue($sTitleAlt)),
353  'medTags' => $sTag,
354  'Categories' => array($sCat),
355  'Type' => $_FILES[$sName]['type'][$i],
356  );
357  $aPathInfo = pathinfo ($_FILES[$sName]['name'][$i]);
358  $sTmpFile = CH_DIRECTORY_PATH_ROOT . 'tmp/v' . time() . getLoggedId() . $i . '.' . $aPathInfo['extension'];
359  if (move_uploaded_file($sUploadedFile, $sTmpFile)) {
360  $iRet = ChWsbService::call('files', 'perform_file_upload', array($sTmpFile, $aFileInfo), 'Uploader');
361  @unlink ($sTmpFile);
362  $sPrice = 0;
363  if (preg_match('/([0-9]+[\.0-9]*)/', $aPrices[$i], $m))
364  $sPrice = $m[1];
365  if ($iRet)
366  $aRet[] = array ('id' => $iRet, 'price' => $sPrice, 'privacy' => $aPrivacy[$i]);
367  }
368  }
369  return $aRet;
370  }
371 
372  function processMedia ($iEntryId, $iProfileId)
373  {
374  parent::processMedia ($iEntryId, $iProfileId);
375 
376  if ($aMedia = $this->uploadFiles(CH_STORE_FILES_TAG, CH_STORE_FILES_CAT)) {
377  $this->_oDb->insertMediaFiles ($iEntryId, $aMedia, $this->_oMain->_iProfileId);
378  }
379  }
380 }
CH_STORE_FILES_TAG
const CH_STORE_FILES_TAG
Definition: ChStoreModule.php:30
ChStoreFormAdd\processMedia
processMedia($iEntryId, $iProfileId)
Definition: ChStoreFormAdd.php:372
$aPathInfo
$aPathInfo
Definition: cmd.php:12
ChWsbRequest\serviceExists
static serviceExists($mixedModule, $sMethod, $sClass="Module")
Definition: ChWsbRequest.php:70
ChWsbForm\getCleanValue
getCleanValue($sName)
Definition: ChWsbForm.php:232
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
ChStoreFormAdd
Definition: ChStoreFormAdd.php:12
ChWsbFormMedia\_getFilesInEntry
_getFilesInEntry($sModuleName, $sServiceMethod, $sName, $sMediaType, $iIdProfile, $iEntryId)
Definition: ChWsbFormMedia.php:219
php
ChStoreFormAdd\$_oMain
$_oMain
Definition: ChStoreFormAdd.php:13
MEMBERSHIP_ID_STANDARD
const MEMBERSHIP_ID_STANDARD
Definition: membership_levels.inc.php:49
getMemberships
getMemberships($purchasableOnly=false)
Definition: membership_levels.inc.php:670
ChWsbCategories
Definition: ChWsbCategories.php:13
ChWsbFormMedia
Definition: ChWsbFormMedia.php:14
getParam
getParam($sParamName, $bUseCache=true)
Definition: db.inc.php:130
ChStoreFormAdd\__construct
__construct($oMain, $iProfileId, $isRemovePhotoFieldAllowed=true, $iEntryId=0, $iThumb=0)
Definition: ChStoreFormAdd.php:16
getLoggedId
getLoggedId()
Definition: profiles.inc.php:32
$sTitle
$sTitle
Definition: actions.inc.php:13
ChStoreFormAdd\uploadFiles
uploadFiles($sTag, $sCat, $sName='files', $sTitle='files_titles', $sTitleAlt='title', $sPrivacy='allow_purchase_to')
Definition: ChStoreFormAdd.php:336
ChStoreFormAdd\$_oDb
$_oDb
Definition: ChStoreFormAdd.php:14
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
time
that in the case of a Adaptation or at a minimum such credit will if a credit for all contributing authors of the Adaptation or Collection then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors For the avoidance of You may only use the credit required by this Section for the purpose of attribution in the manner set out above by exercising Your rights under this You may not implicitly or explicitly assert or imply any connection sponsorship or endorsement by the Original Licensor and or Attribution as of You or Your use of the without the express prior written permission of the Original Licensor and or Attribution Parties Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable if You Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or You must not modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author s honor or reputation Licensor agrees that in those in which any exercise of the right granted in modification or other derogatory action prejudicial to the Original Author s honor and the Licensor will waive or not as this to the fullest extent permitted by the applicable national to enable You to reasonably exercise Your right under Warranties and Disclaimer UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN LICENSOR OFFERS THE WORK AS IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE STATUTORY OR WITHOUT WARRANTIES OF FITNESS FOR A PARTICULAR OR THE ABSENCE OF LATENT OR OTHER OR THE PRESENCE OF ABSENCE OF WHETHER OR NOT DISCOVERABLE SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED SO SUCH EXCLUSION MAY NOT APPLY TO YOU Limitation on Liability EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES Termination This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License Individuals or entities who have received Adaptations or Collections from You under this will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses and will survive any termination of this License Subject to the above terms and the license granted here is Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time
Definition: license.txt:56
CH_WSB_PG_ALL
const CH_WSB_PG_ALL
Definition: ChWsbPrivacy.php:12
CH_STORE_VIDEOS_TAG
const CH_STORE_VIDEOS_TAG
Definition: ChStoreModule.php:27
MEMBERSHIP_ID_NON_MEMBER
const MEMBERSHIP_ID_NON_MEMBER
Definition: membership_levels.inc.php:48
ChWsbFormMedia\processMembershipChecksForMediaUploads
processMembershipChecksForMediaUploads(&$aInputs)
Definition: ChWsbFormMedia.php:366
CH_STORE_PHOTOS_TAG
const CH_STORE_PHOTOS_TAG
Definition: ChStoreModule.php:24
CH_STORE_FILES_CAT
const CH_STORE_FILES_CAT
Definition: ChStoreModule.php:29
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
ChWsbService\call
static call($mixed, $sMethod, $aParams=array(), $sClass='Module')
Definition: ChWsbService.php:32
ChBaseFormView\genInputSelect
genInputSelect(&$aInput)
Definition: ChBaseFormView.php:651
ChWsbFormMedia\generateCustomMediaTemplates
generateCustomMediaTemplates($iProfileId, $iEntryId, $iThumb=0)
Definition: ChWsbFormMedia.php:316
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
$sName
$sName
Definition: ChWsbAdminTools.php:853
$iProfileId
if( $sMembersList) $iProfileId
Definition: communicator.php:29
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
CH_STORE_PHOTOS_CAT
const CH_STORE_PHOTOS_CAT
Definition: ChStoreModule.php:23
CH_STORE_VIDEOS_CAT
const CH_STORE_VIDEOS_CAT
Definition: ChStoreModule.php:26