$s .= '/';
$s .= strtolower( $folder );
}
- if ($s=='basesession'){
- //print_r( debug_backtrace(false));
- debug_print_backtrace();
- die ('zzz');
- }
require_once($s.'.php');
}
return new $model($params);
return new $model();
}
+
+ public static function getUploadPath($params=array()){
+ $upload_path = IPF::get('upload_path', '/tmp');
+ if (isset($params['upload_path'])) {
+ $upload_path = $params['upload_path'];
+ }
+ return $upload_path;
+ }
}
function __($str)
protected function UrlForResult(&$o){
return $o->__get($this->qe->getTable()->getIdentifier()).'/';
}
+
+ protected function _getForm($model_obj, $data, $extra){
+ return IPF_Shortcuts::GetFormForModel($model_obj,$data,$extra);
+ }
+
+ protected function _getEditForm($model_obj, $data, $extra){
+ return $this->_getForm($model_obj, $data, $extra);
+ }
+
+ protected function _getAddForm($model_obj, $data, $extra){
+ return $this->_getForm($model_obj, $data, $extra);
+ }
// Views Function
public function AddItem($request, $lapp, $lmodel){
if ($request->method == 'POST'){
- $form = IPF_Shortcuts::GetFormForModel($this->model,$request->POST+$request->FILES,array('user_fields'=>$this->fields()));
+ $form = $this->_getAddForm($this->model,$request->POST+$request->FILES,array('user_fields'=>$this->fields()));
$this->_setupAddForm($form);
if ($form->isValid()) {
$item = $form->save();
}
}
else{
- $form = IPF_Shortcuts::GetFormForModel($this->model,null,array('user_fields'=>$this->fields()));
+ $form = $this->_getAddForm($this->model,null,array('user_fields'=>$this->fields()));
$this->_setupAddForm($form);
}
$context = array(
public function EditItem($request, $lapp, $lmodel, $o){
if ($request->method == 'POST'){
- $form = IPF_Shortcuts::GetFormForModel($o,$request->POST+$request->FILES,array('user_fields'=>$this->fields()));
+ $form = $this->_getEditForm($o,$request->POST+$request->FILES,array('user_fields'=>$this->fields()));
$this->_setupEditForm($form);
if ( ($form->isValid()) && ($this->isValidInlines()) ) {
$item = $form->save();
}
}
else{
- $form = IPF_Shortcuts::GetFormForModel($o,$o->getData(),array('user_fields'=>$this->fields()));
+ $form = $this->_getEditForm($o,$o->getData(),array('user_fields'=>$this->fields()));
$this->_setupEditForm($form);
}
return false;
}
- function isValid()
- {
+ function isValid(){
if ($this->is_valid !== null) {
return $this->is_valid;
}
function IPF_Form_Field_moveToUploadFolder($value, $params=array())
{
- $upload_path = IPF::get('upload_path', '/tmp');
- if (isset($params['upload_path'])) {
- $upload_path = $params['upload_path'];
- }
+ $upload_path = IPF::getUploadPath($params);
$name = IPF_Utils::cleanFileName($value['name'], $upload_path);
$dest = $upload_path.DIRECTORY_SEPARATOR.$name;
if (!move_uploaded_file($value['tmp_name'], $dest)) {
function IPF_Form_Field_moveImageToUploadFolder($value, $params=array())
{
$name = IPF_Form_Field_moveToUploadFolder($value, $params);
- $upload_path = IPF::get('upload_path', '/tmp');
- if (isset($params['upload_path'])) {
- $upload_path = $params['upload_path'];
- }
+ $upload_path = IPF::getUploadPath($params);
$image = $upload_path.DIRECTORY_SEPARATOR.$name;
if(!getimagesize($image))
function initFields($extra=array())
{
- $this->model = $extra['model'];
+ if (isset($extra['model']))
+ $this->model = $extra['model'];
+ else
+ throw new IPF_Exception_Form(__('Unknown model for form'));
+
if (isset($extra['user_fields']))
$this->user_fields = $extra['user_fields'];
-
$user_fields = $this->fields();
$db_columns = $this->model->getTable()->getColumns();
public function render($name, $value, $extra_attrs=array())
{
- $value = $value['data'];
$sim = '';
- if (is_string($value) && $value!=''){
- $sim = 'Currently: <a target="_blank" href="'.IPF::get('upload_url').$value.'">'.$value.'</a> | <input name="'.$name.'_remove" value="1" id="id_'.$name.'_remove" type="checkbox" /> <label for="id_'.$name.'_remove">Remove</label><br />Change:';
+ if (isset($value['data'])){
+ $value = $value['data'];
+ if (is_string($value) && $value!=''){
+ $sim = 'Currently: <a target="_blank" href="'.IPF::get('upload_url').$value.'">'.$value.'</a> | <input name="'.$name.'_remove" value="1" id="id_'.$name.'_remove" type="checkbox" /> <label for="id_'.$name.'_remove">Remove</label><br />Change:';
+ }
}
$value = '';
return $sim.parent::render($name, $value, $extra_attrs);
protected $ThumbnailWidth, $ThumbnailHeight;
protected $SourceWidth, $SourceHeight, $SourceType;
protected $file_permission, $dir_permission;
+ protected $sourceRemove;
- public function __construct($source, $thumnbail, $width=null, $height=null, $dir_permission=null, $file_permission=null){
+ public function __construct($source, $width=null, $height=null, $thumbnail=null, $sourceRemove=false, $dir_permission=null, $file_permission=null){
$this->Source = $source;
- $this->Thumbnail = $thumbnail;
+ if ($thumbnail)
+ $this->Thumbnail = $thumbnail;
+ else
+ $this->Thumbnail = $source;
if (($width==null) && ($height==null))
throw new IPF_Exception_Image(__('Please Specify width or height'));
$this->file_permission = $file_permission;
else
$this->file_permission = IPF::get('file_permission');
+
+ $this->sourceRemove = $sourceRemove;
}
public function execute(){
$this->ThumbnailWidth, $this->ThumbnailHeight,
$this->SourceWidth, $this->SourceHeight
);
-
- if (!@unlink($this->Thumbnail))
- throw new IPF_Exception_Image(sprintf(__('Cannot delete %s'), $this->Thumbnail));
-
+ if ($this->sourceRemove){
+ if (!@unlink($this->Thumbnail))
+ throw new IPF_Exception_Image(sprintf(__('Cannot delete %s'), $this->Thumbnail));
+ }
$dir_thumbnail = dirName($this->Thumbnail);
if (!IPF_Utils::makeDirectories(dirName($this->Thumbnail), $this->dir_permission))
throw new IPF_Exception_Image(sprintf(__('Cannot create path %s'), $dir_thumbnail));