18 require_once SQ_INCLUDE_PATH.
'/asset_edit/asset_edit_fns.inc';
43 $this->static_screens = Array(
45 'name' => translate(
'details'),
46 'force_unlock' => FALSE,
47 'lock_type' =>
'none',
67 if (!$asset->id && !$wa) {
71 $variety_type = $asset->
attr(
'variety_type');
72 $constrain = $asset->
attr(
'constrain');
74 $int_edit_params =
new SimpleXMLElement(
'<int width="8" />');
75 $bool_edit_params =
new SimpleXMLElement(
'<boolean true_text="yes" false_text="no" />');
76 $sel_edit_params =
new SimpleXMLElement(
'<selection style="box" columns="3" extras="" />');
78 if ($asset->name ==
'') {
80 $text_edit_params =
new SimpleXMLElement(
'<text width="15" />');
82 $attr->setEditParams($text_edit_params);
83 $attr->paint($prefix.
'_'.$attr->name, !$wa);
89 $js_prefix = preg_replace(
'/[^a-z0-9_]/',
'_', $prefix);
91 <script type=
"text/javascript">
94 function <?php echo $js_prefix; ?>_update_visible_fields() {
96 var variety_type = get_form_element_value(
"<?php echo $prefix; ?>_variety_type");
97 var constrain = get_form_element_value(
"<?php echo $prefix; ?>_constrain");
99 document.getElementById(
'<?php echo $prefix; ?>_field_constrain').style.display = (variety_type ==
'resize') ?
'' :
'none';
100 document.getElementById(
'<?php echo $prefix; ?>_field_width').style.display = (variety_type ==
'resize' && (constrain ==
'width' || constrain ==
'none')) ?
'' :
'none';
101 document.getElementById(
'<?php echo $prefix; ?>_field_height').style.display = (variety_type ==
'resize' && (constrain ==
'height' || constrain ==
'none')) ?
'' :
'none';
102 document.getElementById(
'<?php echo $prefix; ?>_field_dimension').style.display = (variety_type ==
'resize' && constrain ==
'dimension') ?
'' :
'none';
103 document.getElementById(
'<?php echo $prefix; ?>_field_upload').style.display = (variety_type ==
'upload') ?
'' :
'none';
111 $sel_edit_params->attributes()->extras =
'onclick="return '.$js_prefix.
'_update_visible_fields();"';
113 $attr->setEditParams($sel_edit_params);
114 $attr->paint($prefix.
'_'.$attr->name, !$wa);
118 $o->
openField(translate(
'constrain_by'),
'',
'', ($variety_type !=
'resize'), $prefix.
'_field_constrain');
119 $sel_edit_params->attributes()->extras =
'onclick="return '.$js_prefix.
'_update_visible_fields();"';
121 $attr->setEditParams($sel_edit_params);
122 $attr->paint($prefix.
'_'.$attr->name, !$wa);
126 $o->
openField(translate(
'width'),
'',
'', ($variety_type !=
'resize' || $constrain !=
'width'), $prefix.
'_field_width');
128 $attr->setEditParams($int_edit_params);
129 $attr->paint($prefix.
'_'.$attr->name, !$wa);
133 $o->
openField(translate(
'height'),
'',
'', ($variety_type !=
'resize' || $constrain !=
'height'), $prefix.
'_field_height');
135 $attr->setEditParams($int_edit_params);
136 $attr->paint($prefix.
'_'.$attr->name, !$wa);
140 $o->
openField(translate(
'dimension'),
'', translate(
'dimension_note'), ($variety_type !=
'resize' || $constrain !=
'dimension'), $prefix.
'_field_dimension');
142 $attr->setEditParams($int_edit_params);
143 $attr->paint($prefix.
'_'.$attr->name, !$wa);
147 $o->
openField(translate(
'upload'),
'',
'', ($variety_type !=
'upload'), $prefix.
'_field_upload');
148 if ($wa) file_upload($prefix.
'_upload_file');
152 $o->
openField(translate(
'current_variety'));
154 <a href=
"<?php echo current_url(TRUE, TRUE).'?a='.$asset->id?>&now=<?php echo time()?>" target=
"_blank"><?php echo translate(
'core_click_to_open_in_new_window'); ?></a>
175 if (!$asset->
writeAccess(
'attributes'))
return FALSE;
177 $changes_made = FALSE;
179 $vars = Array(
'variety_type',
'constrain',
'width',
'height',
'dimension');
180 if ($asset->
attr(
'name') ==
'') {
181 array_unshift($vars,
'name');
184 foreach ($vars as $attr_name) {
186 $attr->process($prefix.
'_'.$attr->name);
187 if ($attr->processed && $asset->
setAttrValue($attr->name, $attr->value)) {
188 $changes_made = TRUE;
192 if ($asset->_imageid && $asset->
attr(
'variety_type') ==
'upload') {
193 $info = get_file_upload_info($prefix.
'_upload_file');
195 $changes_made = TRUE;
199 if (!$changes_made) {
226 if (empty($asset->_imageid))
return FALSE;
227 if ($asset->
attr(
'name') ==
'')
return FALSE;
230 if ($info === FALSE || empty($info)) {
234 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
235 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
236 if (!is_dir($asset->data_path) && !create_directory($asset->data_path)) {
240 $image = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($asset->_imageid);
241 if (is_null($image))
return FALSE;
243 $img_ext = get_file_type($image->name);
244 $upload_ext = get_file_type($info[
'name']);
246 if ($img_ext != $upload_ext) {
247 trigger_localised_error(
'CORE0003', E_USER_WARNING);
251 $d_old_filename = $asset->
attr(
'filename');
252 $d_new_filename = $asset->
attr(
'name').
'.'.$img_ext;
253 $d_old_file = $asset->data_path.
'/'.$d_old_filename;
254 $d_new_file = $asset->data_path.
'/'.$d_new_filename;
257 if ($d_old_filename != $d_new_filename) {
262 $up_to_date = $fv->upToDate($d_new_file);
263 if ($up_to_date & FUDGE_FV_OLD_VERSION) {
264 if (!$fv->checkOut($asset->data_path_suffix.
'/'.$d_new_filename, $asset->data_path)) {
265 trigger_localised_error(
'CORE0103', E_USER_WARNING);
273 if (is_uploaded_file($info[
'tmp_name'])) {
275 if (!move_uploaded_file($info[
'tmp_name'], $d_new_file)) {
276 trigger_localised_error(
'CORE0038', E_USER_WARNING ,$info[
'tmp_name'], $d_new_file);
279 }
else if (isset($info[
'non_uploaded_file']) && $info[
'non_uploaded_file'] === TRUE) {
281 if (!copy($info[
'tmp_name'], $d_new_file)) {
282 trigger_localised_error(
'CORE0036',E_USER_WARNING, $info[
'tmp_name'], $d_new_file);
286 trigger_localised_error(
'CORE0067', E_USER_ERROR);
290 $up_to_date = $fv->upToDate($d_new_file);
293 if ($up_to_date & FUDGE_FV_NOT_CHECKED_OUT) {
294 if (!$fv->add($asset->data_path_suffix, $d_new_file,
'')) {
298 if (!$fv->checkOut($asset->data_path_suffix.
'/'.$d_new_filename, $asset->data_path)) {
299 trigger_localised_error(
'CORE0103', E_USER_WARNING);
303 }
else if ($up_to_date & FUDGE_FV_MODIFIED) {
304 if (!$fv->commit($d_new_file,
''))
return FALSE;
309 if (!$asset->
setAttrValue(
'filename', $d_new_filename)) {