Skip to content

Commit

Permalink
finishing up contacts manager with image uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmatic69 committed Feb 18, 2010
1 parent 08fe51f commit cae9d19
Show file tree
Hide file tree
Showing 11 changed files with 523 additions and 63 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,6 +6,7 @@ plugins/*
libs/cronjobs
.gitignore
views/themed/*
webroot/img/content/contact/*

# If you are using an ide other than below add ignores for the files it creates
# and commit the changes.
Expand Down
4 changes: 3 additions & 1 deletion infinitas/contact/contact_app_controller.php
@@ -1,5 +1,7 @@
<?php
class ContactAppController extends AppController {

var $helpers = array(
'Filter.Filter'
);
}
?>
80 changes: 80 additions & 0 deletions infinitas/contact/controllers/contacts_controller.php
@@ -0,0 +1,80 @@
<?php
/**
* Contacts controller
*
* Used for managing contacts at the company of the site
*
* Copyright (c) 2010 Carl Sutton ( dogmatic69 )
*
* @filesource
* @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 )
* @link http://www.infinitas-cms.org
* @package contact
* @subpackage contact.controllers.contacts
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @since 0.7a
*
* @author Carl Sutton ( dogmatic69 )
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*/

class ContactsController extends ContactAppController{
var $name = 'Contacts';

function admin_index(){
$this->Contact->recursive = 0;

$contacts = $this->paginate(
null,
$this->Filter->filter
);

$filterOptions = $this->Filter->filterOptions;
$filterOptions['fields'] = array(
'name',
'branch_id' => array(null => __('All branches', true)) + $this->Contact->Branch->find('list'),
'active' => (array)Configure::read('CORE.active_options')
);

$this->set(compact('contacts','filterOptions'));
}

function admin_add(){
if (!empty($this->data)) {
$this->Contact->create();
if ($this->Contact->save($this->data)) {
$this->Session->setFlash('Your contact has been saved.');
$this->redirect(array('action' => 'index'));
}
}

$branches = $this->Contact->Branch->find('list');
$this->set(compact('branches'));
}

function admin_edit($id = null){
if (!$id) {
$this->Session->setFlash(__('That contact could not be found', true), true);
$this->redirect($this->referer());
}

if (!empty($this->data)) {
if ($this->Contact->save($this->data)) {
$this->Session->setFlash(__('Your contact has been saved.', true));
$this->redirect(array('action' => 'index'));
}

$this->Session->setFlash(__('Your contact could not be saved.', true));
}

if ($id && empty($this->data)) {
$this->data = $this->Contact->read(null, $id);
}

$branches = $this->Contact->Branch->find('list');
$this->set(compact('branches'));
}
}
?>
55 changes: 53 additions & 2 deletions infinitas/contact/models/branch.php
Expand Up @@ -26,7 +26,7 @@ class Branch extends ContactAppModel{
var $actsAs = array(
'MeioUpload.MeioUpload' => array(
'image' => array(
'dir' => 'img{DS}{plugin}{DS}{model}{DS}{field}',
'dir' => 'img{DS}content{DS}contact{DS}{ModelName}',
'create_directory' => true,
'allowed_mime' => array(
'image/jpeg',
Expand All @@ -40,8 +40,59 @@ class Branch extends ContactAppModel{
),

)
)
),
'Libs.Sequence'
);

var $hasMany = array(
'Contact.Contact'
);

/**
* Construct for validation.
*
* This is used to make the validation messages run through __()
*
* @param mixed $id
* @param mixed $table
* @param mixed $ds
*/
function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);

$this->validate = array(
'name' => array(
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => __('Please enter the name of your branch', true)
),
),
'address' => array(
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => __('Please enter the branches address', true)
)
),
'phone' => array(
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => __('Please enter some text for the body', true)
),
'phone' => array(
'rule' => 'phone',
'message' => __('The number does not seem to be valid', true)
)
),
'fax' => array(
'rule' => 'phone',
'message' => __('Please enter a valid fax number', true),
'allowEmpty' => true
),
'map' => array(
'rule' => 'url',
'message' => __('Please enter a valid url for the map', true)
)
);
}
}
?>
85 changes: 85 additions & 0 deletions infinitas/contact/models/contact.php
@@ -0,0 +1,85 @@
<?php
/**
*
*
*/
class Contact extends ContactAppModel{
var $name = 'Contact';

var $actsAs = array(
'MeioUpload.MeioUpload' => array(
'image' => array(
'dir' => 'img{DS}content{DS}contact{DS}{ModelName}',
'create_directory' => true,
'allowed_mime' => array(
'image/jpeg',
'image/pjpeg',
'image/png'
),
'allowed_ext' => array(
'.jpg',
'.jpeg',
'.png'
),

)
),
'Libs.Sequence' => array(
'group_fields' => array(
'branch_id'
)
)
);

var $belongsTo = array(
'Contact.Branch'
);

/**
* Construct for validation.
*
* This is used to make the validation messages run through __()
*
* @param mixed $id
* @param mixed $table
* @param mixed $ds
*/
function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);

$this->validate = array(
'first_name' => array(
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => __('Please enter the contacts first name', true)
),
),
'last_name' => array(
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => __('Please enter the contacts last name', true)
),
),
'phone' => array(
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => __('Please enter some text for the body', true)
),
'phone' => array(
'rule' => 'phone',
'message' => __('The number does not seem to be valid', true)
)
),
'mobile' => array(
'rule' => 'phone',
'message' => __('Please enter a valid mobile number', true),
'allowEmpty' => true
),
'branch_id' => array(
'rule' => array('comparison', '>', 0),
'message' => __('Please select a branch', true)
)
);
}
}
?>
8 changes: 6 additions & 2 deletions infinitas/contact/views/branches/admin_add.ctp
Expand Up @@ -18,13 +18,17 @@
*/

echo $this->Infinitas->adminOtherHead($this);
echo $this->Form->create('Module', array('type' => 'file'));
echo $this->Form->create('Branch', array('type' => 'file'));
?>
<div style="width:50%; float:left;">
<?php
echo $this->Form->input('id');
echo $this->Form->input('image', array('type' => 'file'));
echo $this->Form->input('name', array('class' => 'title'));
echo $this->Form->input('name');
echo $this->Form->input('phone');
echo $this->Form->input('fax');
echo $this->Form->input('address');
echo $this->Form->input('map');
echo $this->Form->input('active');
?>
</div>
Expand Down
91 changes: 41 additions & 50 deletions infinitas/contact/views/branches/admin_edit.ctp
@@ -1,51 +1,42 @@
<?php
/**
* Management Modules admin edit post.
*
* this page is for admin to manage the modules on the site
*
* Copyright (c) 2009 Carl Sutton ( dogmatic69 )
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright (c) 2009 Carl Sutton ( dogmatic69 )
* @link http://infinitas-cms.org
* @package management
* @subpackage management.views.configs.admin_edit
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/

echo $this->Core->adminOtherHead( $this );
echo $this->Form->create( 'Module' );
?>
<div style="width:50%; float:left;">
<?php
echo $this->Form->input( 'id' );
echo $this->Form->input( 'name' );
echo $this->Form->input( 'module' );
echo $this->Form->input( 'theme_id' );
echo $this->Form->input( 'position_id' );
echo $this->Form->input( 'group_id' );
echo $this->Form->input( 'active' );
echo $this->Form->input( 'show_heading' );
echo $this->Form->input( 'core' );
echo $this->Form->input( 'author' );
echo $this->Form->input( 'url' );
echo $this->Form->input( 'update_url' );
echo $this->Form->input( 'licence' );

echo $this->Form->input( 'content', array('class' => 'title') );
echo $this->Form->input( 'config', array('class' => 'title') );
?>
</div>
<div style="width:50%; float:left;">
<?php
echo $this->Form->input('Route');
?>
</div>
<div class="clr">&nbsp;</div>
<?php
echo $this->Form->end( 'Save Module' );
<?php
/**
* Management Modules admin edit post.
*
* this page is for admin to manage the modules on the site
*
* Copyright (c) 2009 Carl Sutton ( dogmatic69 )
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright (c) 2009 Carl Sutton ( dogmatic69 )
* @link http://infinitas-cms.org
* @package management
* @subpackage management.views.configs.admin_edit
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/

echo $this->Infinitas->adminOtherHead($this);
echo $this->Form->create('Branch', array('type' => 'file'));
?>
<div style="width:50%; float:left;">
<?php
echo $this->Form->input('id');
echo $this->Form->input('image', array('type' => 'file'));
echo $this->Form->input('name');
echo $this->Form->input('phone');
echo $this->Form->input('fax');
echo $this->Form->input('address');
echo $this->Form->input('map');
echo $this->Form->input('active');
?>
</div>
<div style="width:50%; float:left;">
<?php
?>
</div>
<div class="clr">&nbsp;</div>
<?php
echo $this->Form->end( 'Save Module' );
?>

0 comments on commit cae9d19

Please sign in to comment.