public static function urls(){
return array(
array('regex'=>'$#', 'func'=>'IPF_Admin_Views_Index'),
- array('regex'=>'([\w\_]+)/([\w\_]+)/$#i', 'func'=>'IPF_Admin_Views_ListItems'),
- array('regex'=>'([\w\_]+)/([\w\_]+)/add/$#i', 'func'=>'IPF_Admin_Views_AddItem'),
- array('regex'=>'([\w\_]+)/([\w\_]+)/([\w\_]+)/$#i', 'func'=>'IPF_Admin_Views_EditItem'),
- array('regex'=>'([\w\_]+)/([\w\_]+)/([\w\_]+)/delete/$#i', 'func'=>'IPF_Admin_Views_DeleteItem'),
- array('regex'=>'auth/user/([\w\_]+)/password/$#i', 'func'=>'IPF_Admin_Views_ChangePassword'),
+ array('regex'=>'([\w\_\-]+)/([\w\_\-]+)/$#i', 'func'=>'IPF_Admin_Views_ListItems'),
+ array('regex'=>'([\w\_\-]+)/([\w\_\-]+)/add/$#i', 'func'=>'IPF_Admin_Views_AddItem'),
+ array('regex'=>'([\w\_\-]+)/([\w\_\-]+)/([\w\_\-]+)/$#i', 'func'=>'IPF_Admin_Views_EditItem'),
+ array('regex'=>'([\w\_\-]+)/([\w\_\-]+)/([\w\_\-]+)/delete/$#i', 'func'=>'IPF_Admin_Views_DeleteItem'),
+ array('regex'=>'auth/user/([\w\_\-]+)/password/$#i', 'func'=>'IPF_Admin_Views_ChangePassword'),
array('regex'=>'login/$#i', 'func'=>'IPF_Admin_Views_Login'),
array('regex'=>'logout/$#i', 'func'=>'IPF_Admin_Views_Logout'),
);
table thead th.descending a { background:url(../img/arrow-up.gif) right .4em no-repeat; }
/* MODULES */
-.module { border:1px solid #ABB0BE; margin-bottom:5px; }
+.module { border:1px solid #ABB0BE; margin-bottom:5px; border-top:none; }
.module p, .module ul, .module h3, .module h4, .module dl, .module pre { padding-left:10px; padding-right:10px; }
.module blockquote { margin-left:12px; }
.module ul, .module ol { margin-left:1.5em; }
-.module h2, .module caption { border-bottom:1px solid #ABB0BE; margin:0; padding:2px 5px 3px 5px; font-size:11px; text-align:left; background:url(../img/hbg.gif) left top repeat-x; color:#444444; font-weight:bold; }
+.module h2, .module caption { border-bottom:1px solid #ABB0BE; border-top:1px solid #ABB0BE; margin:0; padding:2px 5px 3px 5px; font-size:11px; text-align:left; background:url(../img/hbg.gif) left top repeat-x; color:#444444; font-weight:bold; }
.module caption { border:1px solid #ABB0BE; }
.module h3 { margin-top:.6em; }
#ipfcontent-related .module h2 { background:#eee url(../img/nav-bg.gif) bottom left repeat-x; color:#666; }
#ipfcontent-main .verbose .actionlist { float:right; font-size:10px; width:17em; position:relative; top:-1.6em; margin:0 8px; }
/* DASHBOARD */
-.dashboard .module table th { width:100%; }
-.dashboard .module table td { white-space:nowrap; }
+
+.dashboard .module table th { width:100%;}
+.dashboard .module table td { white-space:nowrap;}
.dashboard .module table td a { display:block; padding-right:.6em; }
/* RECENT ACTIONS MODULE */
public function AddItem($request, $lapp, $lmodel){
$model = new $this->modelName();
if ($request->method == 'POST'){
- $form = IPF_Shortcuts::GetFormForModel($model,$request->POST,array('user_fields'=>$this->fields()));
+ $form = IPF_Shortcuts::GetFormForModel($model,$request->POST+$request->FILES,array('user_fields'=>$this->fields()));
$this->_setupAddForm(&$form);
if ($form->isValid()) {
$item = $form->save();
public function EditItem($request, $lapp, $lmodel, $o){
if ($request->method == 'POST'){
- $form = IPF_Shortcuts::GetFormForModel($o,$request->POST,array('user_fields'=>$this->fields()));
+ $form = IPF_Shortcuts::GetFormForModel($o,$request->POST+$request->FILES,array('user_fields'=>$this->fields()));
$this->_setupEditForm(&$form);
if ($form->isValid()) {
$item = $form->save();
else{
$form = IPF_Shortcuts::GetFormForModel($o,$o->getData(),array('user_fields'=>$this->fields()));
$this->_setupEditForm(&$form);
+ $dd = $o->getData();
}
$context = array(
'page_title'=>'Edit '.$this->modelName,
<div id="ipfcontent">
<h1>{$page_title}</h1>
- <form method="post" action="">
+ <form method="post" {if $form.hasFileField() }enctype="multipart/form-data"{/if}>
<fieldset>
<table>
{$form.render_table}
<div id="ipfcontent">
<h1>{$page_title}</h1>
- <form method="post">
+ <form method="post" {if $form.hasFileField() }enctype="multipart/form-data"{/if}>
<fieldset>
<table>
{$form.render_table}
<?php
function checkAdminAuth($request){
+ $ok = true;
if ($request->user->isAnonymous())
+ $ok = false;
+ elseif ( (!$request->user->is_staff) && (!$request->user->is_superuser) )
+ $ok = false;
+
+ if ($ok)
+ return true;
+ else
return new IPF_HTTP_Response_Redirect(IPF_HTTP_URL_urlForView('IPF_Admin_Views_Login'));
- return true;
}
function IPF_Admin_Views_Index($request, $match){
if (false === ($user = $users->checkCreditentials($form->cleaned_data['username'], $form->cleaned_data['password']))) {
$form->message = __('The login or the password is not valid. The login and the password are case sensitive.');
} else {
- $request->user = $user;
- $request->session->clear();
- $request->session->setData('login_time', gmdate('Y-m-d H:i:s'));
- $user->last_login = gmdate('Y-m-d H:i:s');
- $user->save();
+ IPF_Auth_App::login($request, $user);
return new IPF_HTTP_Response_Redirect($success_url);
}
}
}
function IPF_Admin_Views_Logout($request, $match){
- $request->user = new User();
- $request->session->clear();
- $request->session->setData('logout_time', gmdate('Y-m-d H:i:s'));
-
+ IPF_Auth_App::logout($request);
$context = array(
'page_title' => __('IPF Administration'),
);
<?php
class IPF_Auth_App extends IPF_Application{
+
public function __construct(){
parent::__construct(array(
'models'=>array('User','Role')
));
}
+
+ static function login($request, $user){
+ $request->user = $user;
+ $request->session->clear();
+ $request->session->setData('login_time', gmdate('Y-m-d H:i:s'));
+ $user->last_login = gmdate('Y-m-d H:i:s');
+ $user->save();
+ }
+
+ static function logout($request){
+ $request->user = new User();
+ $request->session->clear();
+ $request->session->setData('logout_time', gmdate('Y-m-d H:i:s'));
+ }
}
\ No newline at end of file
<?php
class IPF_Auth_Forms_Login extends IPF_Form{
+ var $message = null;
function initFields($extra=array()){
$this->fields['username'] = new IPF_Form_Field_Varchar(array('required'=>true));
$this->fields['password'] = new IPF_Form_Field_Varchar(array('required'=>true,'widget'=>'IPF_Form_Widget_PasswordInput'));
return 'Anonymous';
return $s;
}
+
+ public function smartName() {
+ $username = $this->username;
+ if ($username===null)
+ return __('Anonymous');
+ $name = $this->first_name.' '.$this->last_name;
+ if (trim($name)=='')
+ return $username;
+ return $name;
+ }
static function createUser($username, $password=null, $email=null, $first_name=null, $last_name=null, $is_active=false, $is_staff=false, $is_superuser=false){
$user = new User();
}
}
-IPF_Admin_Model::register(User,AdminUser);
+IPF_Admin_Model::register('User','AdminUser');
public $label_suffix = ':';
protected $is_valid = null;
+
function __construct($data=null, $extra=array(), $label_suffix=null)
{
}
return $field_name;
}
+
+ function hasFileField(){
+ foreach($this->fields as $field){
+ if (is_a($field,'IPF_Form_Field_File')){
+ return true;
+ }
+ }
+ return false;
+ }
function isValid()
{
--- /dev/null
+<?php
+
+class IPF_Form_DB_File extends IPF_Form_DB{
+ function formField($def, $form_field='IPF_Form_Field_File'){
+ return parent::formField($def, $form_field);
+ }
+}
--- /dev/null
+<?php
+
+class IPF_Form_DB_Image extends IPF_Form_DB{
+ function formField($def, $form_field='IPF_Form_Field_Image'){
+ return parent::formField($def, $form_field);
+ }
+}
$default = array();
foreach ($params as $key=>$in) {
if ($key !== 'widget_attrs')
- $default[$key] = $this->$key;
+ if (isset($this->$key))
+ $default[$key] = $this->$key;
}
$m = array_merge($default, $params);
foreach ($params as $key=>$in) {
if ($key !== 'widget_attrs')
$this->$key = $m[$key];
}
- $widget_name = $this->widget;
+ $widget_name = $this->getWidget();
if (isset($params['widget_attrs'])) {
$attrs = $params['widget_attrs'];
} else {
}
return $value;
}
+
+ protected function getWidget(){
+ return $this->widget;
+ }
public function widgetAttrs($widget)
{
function clean($value)
{
+ if ($value['name']=='')
+ return '';
+
parent::clean($value);
+
$errors = array();
$no_files = false;
switch ($value['error']) {
if (isset($params['upload_path'])) {
$upload_path = $params['upload_path'];
}
- $dest = $upload_path.'/'.$name;
- if (!@move_uploaded_file($value['tmp_name'], $dest)) {
+ $dest = $upload_path.DIRECTORY_SEPARATOR.$name;
+ if (!move_uploaded_file($value['tmp_name'], $dest)) {
throw new IPF_Exception_Form(__('An error occured when upload the file. Please try to send the file again.'));
}
@chmod($dest, 0666);
public function clean($value)
{
parent::clean($value);
+
if (in_array($value, $this->empty_values)) {
$value = '';
}
$_value = $value;
$value = (float) $value;
- if ((string) $value !== (string) $_value) {
+
+ if (!is_numeric($value)) {
throw new IPF_Exception_Form(__('Enter a number.'));
}
if ($this->max_value !== null and $this->max_value < $value) {
--- /dev/null
+<?php
+
+class IPF_Form_Field_Image extends IPF_Form_Field_File{
+ public $widget = 'IPF_Form_Widget_Image';
+}
}
return array();
}
+
+ protected function getWidget(){
+ if ($this->max_length>255)
+ return 'IPF_Form_Widget_TextAreaInput';
+ return $this->widget;
+ }
}
}
else{
foreach($user_fields as $uname){
+ $add_method = 'add__'.$uname.'__field';
+ if (method_exists($this->model,$add_method)){
+ //print $add_method;
+ $this->$add_method();
+ continue;
+ }
if (array_key_exists($uname,$db_columns))
$this->addDBField($uname,$db_columns[$uname]);
elseif (array_key_exists($uname,$db_relations))
$this->addDBRelation($uname,$db_relations[$uname]);
- else{
- $add_method = 'add__'.$uname.'__field';
- $this->$add_method();
- }
}
}
}
$defaults['max_length'] = (int)($col['length']);
if (isset($col['email']))
$type = 'email';
+
+ if (isset($col['file']))
+ $type = 'file';
+
+ if (isset($col['image']))
+ $type = 'image';
+
$cn = 'IPF_Form_DB_'.$type;
$db_field = new $cn('', $name);
//echo $name;
//print_r($defaults);
+
+
+
if (null !== ($form_field=$db_field->formField($defaults))) {
$this->fields[$name] = $form_field;
function addDBRelation($name,$relation){
if ($relation->getType()==IPF_ORM_Relation::ONE_AGGREGATE){
- //$name .= "_id";
+ $name .= "_id";
$db_field = new IPF_Form_DB_Foreignkey('',$name);
$defaults = array('blank' => true, 'verbose' => $name, 'help_text' => '', 'editable' => true, 'model'=>$relation->getClass());
$form_field = $db_field->formField($defaults);
}
*/
- $this->model->save();
- return $this->model;
+ try{
+ $this->model->save();
+ return $this->model;
+ } catch(IPF_ORM_Exception_Validator $e) {
+ $erecords = $e->getInvalidRecords();
+ $errors = $erecords[0]->getErrorStack();
+ print_r($this->cleaned_data);
+ foreach($errors as $k=>$v){
+ print_r($v);
+ }
+ //die('zz');
+ }
}
- throw new Exception(__('Cannot save the model from an invalid form.'));
+ throw new IPF_Exception_Form(__('Cannot save the model from an invalid form.'));
}
}
$value = '';
return parent::render($name, $value, $extra_attrs);
}
+
+ public function valueFromFormData($name, $data)
+ {
+ if (isset($data[$name])) {
+ return $data[$name];
+ }
+ return null;
+ }
+
}
\ No newline at end of file
--- /dev/null
+<?php
+
+class IPF_Form_Widget_Image extends IPF_Form_Widget_FileInput
+{
+ public function render($name, $value, $extra_attrs=array())
+ {
+ if ($value!='')
+ $sim = 'Currently: <a target="_blank" href="'.IPF::get('upload_url').$value.'">'.$value.'</a><br />Change:';
+ $value = '';
+ return $sim.parent::render($name, $value, $extra_attrs);
+ }
+}
\ No newline at end of file
return null;
}
- function SetFromFormData($cleaned_values)
+ public function SetFromFormData($cleaned_values)
{
- //$relations = $this->getTable()->getRelations();
foreach ($cleaned_values as $key=>$val) {
- /*
- if (array_key_exists($key,$relations)){
-
-
- }else*/
- $this->$key = $val;
+ $validators = $this->getTable()->getFieldValidators($key);
+ if (array_key_exists('image',$validators) || array_key_exists('file',$validators)){
+ if ($val=='')
+ continue;
+ }
+ $this->$key = $val;
}
}
}
\ No newline at end of file
$columnName = $this->getColumnName($fieldName);
// this loop is a dirty workaround to get the validators filtered out of
// the options, since everything is squeezed together currently
+
+ if (!isset($this->_columns[$columnName]))
+ return array();
+
foreach ($this->_columns[$columnName] as $name => $args) {
if (empty($name)
|| $name == 'primary'
'unique',
'unsigned',
'usstate',
+ 'file',
+ 'image',
);
}
--- /dev/null
+<?php
+
+class IPF_ORM_Validator_File
+{
+ public function validate($value){
+ return true;
+ }
+}
\ No newline at end of file
--- /dev/null
+<?php
+
+class IPF_ORM_Validator_Image
+{
+ public function validate($value){
+ return true;
+ }
+}
\ No newline at end of file
throw new IPF_HTTP_Error404();
}
- static function RenderToResponse($tplfile, $params, $request=null)
- {
+ static function RenderToResponse($tplfile, $params=array(), $request=null){
+ return new IPF_HTTP_Response(IPF_Shortcuts::RenderToString($tplfile, $params, $request));
+ }
+
+ static function RenderToString($tplfile, $params=array(), $request=null){
$tmpl = new IPF_Template($tplfile);
if (is_null($request)) {
$context = new IPF_Template_Context($params);
} else {
$context = new IPF_Template_Context_Request($request, $params);
}
- return new IPF_HTTP_Response($tmpl->render($context));
+ return $tmpl->render($context);
}
static function GetFormForModel($model, $data=null, $extra=array(), $label_suffix=null)
}
static function humanTitle($s){
- return ucfirst(str_replace('_',' ',$s));
+ return ucfirst(str_replace('_',' ',str_replace('_id','',$s)));
}
static function randomString($len=35)
<?php
final class IPF_Version{
- static $name = '0.2 alpha';
+ static $name = '0.3 alpha';
}
\ No newline at end of file