1: <?php
  2: 
  3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13: 
 14: 
 15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 16: 
 17: cInclude('includes', 'functions.upl.php');
 18: 
 19: 
 20: $filename = cSecurity::escapeString($_REQUEST['file']);
 21: $filename = str_replace('"', '', $filename);
 22: $filename = str_replace("'", '', $filename);
 23: 
 24: 
 25: $pathname = cSecurity::escapeString($_REQUEST['path']);
 26: $pathname = str_replace('"', '', $pathname);
 27: $pathname = str_replace("'", '', $pathname);
 28: 
 29: $isZipFile = isArchive($filename);
 30: 
 31: $page = new cGuiPage('upl_edit');
 32: 
 33: $page->addStyle('jquery/plugins/timepicker.css');
 34: $page->addScript('jquery/plugins/timepicker.js');
 35: $page->addScript('include.upl_edit.js');
 36: 
 37: 
 38: if (($lang_short = cString::getPartOfString(cString::toLowerCase($belang), 0, 2)) != 'en') {
 39:     $page->addScript('jquery/plugins/timepicker-' . $lang_short . '.js');
 40:     $page->addScript('jquery/plugins/datepicker-' . $lang_short . '.js');
 41: }
 42: 
 43: $form = new cGuiTableForm('properties');
 44: $form->setVar('frame', $frame);
 45: $form->setVar('area', 'upl');
 46: $form->setVar('path', $pathname);
 47: $form->setVar('file', $filename);
 48: $form->setVar('action', 'upl_modify_file');
 49: $form->setVar('startpage', cSecurity::toInteger($_REQUEST['startpage']));
 50: $form->setVar('sortby', cSecurity::escapeString($_REQUEST['sortby']));
 51: $form->setVar('sortmode', cSecurity::escapeString($_REQUEST['sortmode']));
 52: $form->setVar('thumbnailmode', cSecurity::escapeString($_REQUEST['thumbnailmode']));
 53: 
 54: $form->addHeader(i18n('Edit'));
 55: 
 56: $properties = new cApiPropertyCollection();
 57: $uploads = new cApiUploadCollection();
 58: 
 59: if (cApiDbfs::isDbfs($_REQUEST['path'])) {
 60:     $qpath = $pathname . '/';
 61: } else {
 62:     $qpath = $pathname;
 63: }
 64: 
 65: if ((is_writable($cfgClient[$client]['upl']['path'] . $path) || cApiDbfs::isDbfs($path)) && (int) $client > 0) {
 66:     $bDirectoryIsWritable = true;
 67: } else {
 68:     $bDirectoryIsWritable = false;
 69: }
 70: 
 71: $uploads->select("idclient = '" . $client . "' AND dirname = '" . $qpath . "' AND filename='" . $filename . "'");
 72: 
 73: if ($upload = $uploads->next()) {
 74: 
 75:     
 76:     $aListRows = array();
 77:     $aListRows['filename'] = i18n('File name');
 78:     $aListRows['path'] = i18n('Path');
 79:     $aListRows['replacefile'] = i18n('Replace file');
 80:     $aListRows['medianame'] = i18n('Media name');
 81:     $aListRows['description'] = i18n('Description');
 82:     $aListRows['keywords'] = i18n('Keywords');
 83:     $aListRows['medianotes'] = i18n('Internal notes');
 84:     $aListRows['copyright'] = i18n('Copyright');
 85:     $aListRows['protected'] = i18n('Protection');
 86:     $aListRows['timecontrol'] = i18n('Time control');
 87:     $aListRows['preview'] = i18n('Preview');
 88:     $aListRows['author'] = i18n('Author');
 89:     $aListRows['modified'] = i18n('Last modified by');
 90: 
 91:     if ($isZipFile) {
 92:         $id = $_GET['user_id'];
 93:         
 94: 
 95:         if (isset($_SESSION['zip']) && $_SESSION['zip'] === 'extract') {
 96: 
 97:         }
 98: 
 99:         $link = new cHTMLLink();
100:         $link->appendContent(i18n('extract'));
101:         $aListRows['zip'] = $link;
102:     }
103:     ($isZipFile) ? $aListRows['extractFolder'] = '<label class="ZipExtract">' . i18n('extractTo') . '</label>' : '';
104: 
105:     
106:     if (!cApiDbfs::isDbfs($_REQUEST['path'])) {
107:         unset($aListRows['protected']);
108:         unset($aListRows['timecontrol']);
109:     }
110: 
111:     
112:     $_cecIterator = $_cecRegistry->getIterator('Contenido.Upl_edit.Rows');
113:     if ($_cecIterator->count() > 0) {
114:         while ($chainEntry = $_cecIterator->next()) {
115:             $newRowList = $chainEntry->execute($aListRows);
116:             if (is_array($newRowList)) {
117:                 $aListRows = $newRowList;
118:             }
119:         }
120:     }
121: 
122:     $iIdupl = $upload->get('idupl');
123: 
124:     $uploadMeta = new cApiUploadMeta();
125:     $uploadMeta->loadByUploadIdAndLanguageId($iIdupl, $lang);
126: 
127:     
128:     foreach ($aListRows as $sListRow => $sTitle) {
129:         $sCell = '';
130:         switch ($sListRow) {
131:             case 'filename':
132:                 $sCell = $filename;
133:                 break;
134: 
135:             case 'zip':
136:                 $sCell = new cHTMLCheckbox('extractZip', '');
137:                 $sCell->setEvent('onclick', 'show();');
138:                 
139:                 break;
140: 
141:             case 'extractFolder':
142:                 $box = new cHTMLTextbox('efolder');
143:                 $box->setID('extractFolder');
144:                 $box->setValue(strstr($filename, '.', TRUE));
145:                 $box->setClass('ZipExtract');
146:                 $sCell = $box;
147:                 $checkbox = new cHTMLCheckbox('overwrite', i18n('overwrite'));
148:                 $checkbox->setID('overwrite');
149:                 $checkbox->setLabelText(i18n('overwrite'));
150:                 $checkbox->setClass('ZipExtract');
151: 
152:                 $sCell .= $checkbox;
153:                 break;
154: 
155:             case 'path':
156:                 $sCell = generateDisplayFilePath($qpath, 65);
157:                 break;
158: 
159:             case 'replacefile':
160:                 $uplelement = new cHTMLUpload('file', 40);
161:                 $uplelement->setDisabled(!$bDirectoryIsWritable);
162:                 $sCell = $uplelement->render();
163:                 break;
164: 
165:             case 'medianame':
166: 
167:                 if ($uploadMeta->get('medianame')) {
168:                     $medianame = cSecurity::unFilter($uploadMeta->get('medianame'));
169:                 } else {
170:                     $medianame = $properties->getValue('upload', $qpath . $filename, 'file', 'medianame');
171:                 }
172: 
173:                 $mnedit = new cHTMLTextbox('medianame', conHtmlentities($medianame), 60);
174:                 $sCell = $mnedit->render();
175:                 break;
176: 
177:             case 'description':
178:                 if ($uploadMeta->get('description')) {
179:                     $description = cSecurity::unFilter($uploadMeta->get('description'));
180:                 } else {
181:                     $description = '';
182:                 }
183: 
184:                 $dsedit = new cHTMLTextarea('description', $description);
185:                 $sCell = $dsedit->render();
186:                 break;
187: 
188:             case 'keywords':
189:                 if ($uploadMeta->get('keywords')) {
190:                     $keywords = cSecurity::unFilter($uploadMeta->get('keywords'));
191:                 } else {
192:                     $keywords = $properties->getValue('upload', $qpath . $filename, 'file', 'keywords');
193:                 }
194: 
195:                 $kwedit = new cHTMLTextarea('keywords', $keywords);
196:                 $sCell = $kwedit->render();
197:                 break;
198: 
199:             case 'medianotes':
200:                 if ($uploadMeta->get('internal_notice')) {
201:                     $medianotes = cSecurity::unFilter($uploadMeta->get('internal_notice'));
202:                 } else {
203:                     $medianotes = $properties->getValue('upload', $qpath . $filename, 'file', 'medianotes');
204:                 }
205: 
206:                 $moedit = new cHTMLTextarea('medianotes', $medianotes);
207:                 $sCell = $moedit->render();
208:                 break;
209: 
210:             case 'copyright':
211:                 if ($uploadMeta->get('copyright')) {
212:                     $copyright = cSecurity::unFilter($uploadMeta->get('copyright'));
213:                 } else {
214:                     $copyright = $properties->getValue('upload', $qpath . $filename, 'file', 'copyright');
215:                 }
216: 
217:                 $copyrightEdit = new cHTMLTextarea('copyright', $copyright);
218:                 $sCell = $copyrightEdit->render();
219:                 break;
220: 
221:             case 'protected':
222:                 $vprotected = $properties->getValue('upload', $qpath . $filename, 'file', 'protected');
223:                 $protected = new cHTMLCheckbox('protected', '1');
224:                 $protected->setChecked($vprotected);
225:                 $protected->setLabelText(i18n('Protected for non-logged in users'));
226:                 $sCell = $protected->render();
227:                 break;
228: 
229:             case 'timecontrol':
230:                 $iTimeMng = (int) $properties->getValue('upload', $qpath . $filename, 'file', 'timemgmt');
231:                 $sStartDate = $properties->getValue('upload', $qpath . $filename, 'file', 'datestart');
232:                 $sEndDate = $properties->getValue('upload', $qpath . $filename, 'file', 'dateend');
233: 
234:                 $oTimeCheckbox = new cHTMLCheckbox('timemgmt', '1');
235:                 $oTimeCheckbox->setChecked($iTimeMng);
236:                 $oTimeCheckbox->setLabelText(i18n('Use time control'));
237: 
238:                 $sHtmlTimeMng = $oTimeCheckbox->render();
239:                 $sHtmlTimeMng .= "<table id='dbfsTimecontrol' class='borderless' border='0' cellpadding='0' cellspacing='0'>\n";
240:                 $sHtmlTimeMng .= "<tr><td><label for='datestart'>" . i18n('Start date') . "</label></td>\n";
241:                 $sHtmlTimeMng .= '<td><input type="text" name="datestart" id="datestart" value="' . $sStartDate . '"  size="20" maxlength="40" class="text_medium">' .
242:                         '</td></tr>';
243:                 $sHtmlTimeMng .= "<tr><td><label for='dateend'>" . i18n('End date') . "</label></td>\n";
244:                 $sHtmlTimeMng .= '<td><input type="text" name="dateend" id="dateend" value="' . $sEndDate . '"  size="20" maxlength="40" class="text_medium">' .
245:                         '</td></tr>';
246:                 $sHtmlTimeMng .= "</table>\n";
247: 
248:                 $sCell = $sHtmlTimeMng;
249:                 break;
250: 
251:             case 'preview':
252:                 if (cApiDbfs::isDbfs($_REQUEST['path'])) {
253:                     $sCell = '<a target="_blank" href="' . cRegistry::getFrontendUrl() . "dbfs.php?file=" . $qpath . $filename . '"><img alt="" class="bordered" src="' . uplGetThumbnail($qpath . $filename, 350) . '"></a>';
254:                 } else {
255:                     $sCell = '<a target="_blank" href="' . $cfgClient[$client]['upl']['htmlpath'] . $qpath . $filename . '"><img alt="" class="bordered" src="' . uplGetThumbnail($qpath . $filename, 350) . '"></a>';
256:                 }
257:                 break;
258: 
259:             case 'author':
260:                 $oUser = new cApiUser($upload->get('author'));
261:                 $sCell = $oUser->get('username') . ' (' . displayDatetime($upload->get('created')) . ')';
262:                 break;
263: 
264:             case 'modified':
265:                 $oUser = new cApiUser($upload->get('modifiedby'));
266:                 $sCell = $oUser->get('username') . ' (' . displayDatetime($upload->get('lastmodified')) . ')';
267:                 break;
268: 
269:             default:
270:                 
271:                 $_cecIterator = $_cecRegistry->getIterator('Contenido.Upl_edit.RenderRows');
272: 
273:                 if ($_cecIterator->count() > 0) {
274:                     $contents = array();
275:                     while ($chainEntry = $_cecIterator->next()) {
276:                         $contents[] = $chainEntry->execute($iIdupl, $qpath, $filename, $sListRow);
277:                     }
278:                 }
279:                 $sCell = implode('', $contents);
280:         }
281:         $form->add($sTitle, $sCell);
282:     }
283: 
284:     if ($bDirectoryIsWritable == false) {
285:         $pager->displayError(i18n('Directory not writable') . ' (' . $cfgClient[$client]['upl']['path'] . $path . ')');
286:     }
287: 
288:     $page->set('s', 'FORM', $form->render());
289: } else {
290:     $page->displayCriticalError(sprintf(i18n('Could not load file %s'), $filename));
291: }
292: 
293: $page->render();
294: 
295: 296: 297: 298: 299: 
300: function isArchive($fileName)
301: {
302:     if (cString::getPartOfString(cString::findLastOccurrence($fileName, '.'), 1) === 'zip') {
303:         return true;
304:     } else {
305:         return false;
306:     }
307: }
308: