Andras,
On Saturday, August 23, 2014 5:47:08 PM UTC-4, Dallas wrote:
-- I made the changes you suggested to both files but I am still getting same error - here is all code for both files - I am most appreciative of your help.
view error at http://musicthatjumpedtheshark.com/groups
GroupsController.php
<?php
include_once 'includes/defines.php';
require_once('includes/recaptchalib.php');
include_once 'includes/base_app_controller.php';
include('includes/functions.php');
/**
* page descriptions
*
* /index - public: home page
* /admin - administration: home page (list and add groups)
* /glist - administration: displays a list of groups
* /gedit - administration: edit/delete a single group
// function ggenres($id = null)
// function goptions($group_id = null, $action = null, $option_id = null)
// function gcomments($group_id = null, $action = null, $comment_id = null)
*
*/
class GroupsController extends BaseAppController
{
public $name = 'Groups';
public $helpers = array('Html', 'Form', 'Session' );
public $components = array('Session', 'RequestHandler');
public $uses = array('Group', 'Genre', 'GenreGroup', 'Option', 'Comment', 'Blog', 'BlogComments');
public $query;
public $top_ad_links;
public $side_ad_links;
// Pass through the request and response objects
// AND declare the visibility of the method
public function __construct($request = null, $response = null)
{
parent::__construct($request, $response);
}
$this->layout = 'home';
$this->set('title_for_layout', 'Music That Jumped the Shark ~ groups');
// get the random ad links
include('includes/ad_selection.php');
$this->set('top_ads', $_ads_top_link);
$this->set('side_ads', $_ads_side_link);
$this->top_ad_links = $_ads_top_link;
$this->side_ad_links = $_ads_side_link;
}
// DEBUG
public function under_construction()
{
$this->layout = 'temp';
}
/**
* PUBLIC PAGES
*/
public function index()
{
$this->require_http();
// find all genre
$fields = array('id','genre');
$order = 'genre ASC';
$genres = $this->Genre->find('all', array('fields'=>$fields, 'order'=>$order));
$this->set('genres', $genres);
// find all groups & select one at random
$groups = $this->Group->find('all', array('fields'=>array('id', 'prefix', 'name', 'file_size')));
$count = count($groups);
$rand = rand(0, (count($groups) - 1));
if($count == 0)
{
$this->set('rand_group', null);
}
else
{
$rand_row = $groups[$rand];
// $rand_row = $groups[9];
$this->set('rand_group', $rand_row);
$fields = array('comment', 'name', 'city','state');
$cond = array('group_id'=>$rand_row['Group']['id']);
$comments = $this->Comment->find('all', array('conditions'=>$cond, 'fields'=>$fields, 'order'=>'date desc'));
$this->set('comments', $comments);
}
// get the latest blog
$image = ' ';
$image .= $this->top_ad_links[1];
// get the latest blog
$fields = array('id', 'content', 'title','date');
$cond = array('order'=>'date desc', 'limit'=> 1);
$blog = $this->Blog->find('all', array('order'=>'date desc', 'limit'=>1, 'fields'=>$fields));
if(count($blog) > 0)
{
$this->set('blog_id', $blog[0]['Blog']['id']);
$this->set('blog_title', $blog[0]['Blog']['title']);
$this->set('blog_content', blog_formatter($blog[0]['Blog']['content'],$image));
$this->set('blog_date', date('F j, Y', strtotime($blog[0]['Blog']['date'])));
$cond = array('blog_id' => $blog[0]['Blog']['id'], 'flag' => 'approved');
$count = $this->BlogComments->find('count', array('conditions' => $cond));
$this->set('blog_comment_count', $count);
}
// clear the selection list link
$this->Session->delete('selection_link');
}
public function select($action = null, $action_var = null)
{
$results = array();
if(isset($this->data['Group']['by_genre']))
{
$action = 'genre';
$action_var = $this->data['Group']['genre'];
}
elseif(isset($this->data['Group']['find_form']))
{
$action = 'prefix';
$action_var = $this->data['Group']['f_name'];
}
switch($action)
{
default:
// no action - go back to home page
$this->redirect(SITE_HREF.'/groups');
break;
case 'prefix':
// select by prefix
$fields = array('id', 'prefix', 'name', 'votes', 'views');
$conditions = array('name like '=>$action_var.'%');
$groups = $this->Group->find('all', array('conditions'=>$conditions, 'fields'=>$fields));
break;
case 'digit':
// select all groups beginning with a digit
$fields = array('id', 'prefix', 'name', 'votes', 'views');
$conditions = array('OR' =>array(
array('name like'=>'0%'),
array('name like'=>'1%'),
array('name like'=>'2%'),
array('name like'=>'3%'),
array('name like'=>'4%'),
array('name like'=>'5%'),
array('name like'=>'6%'),
array('name like'=>'7%'),
array('name like'=>'8%'),
array('name like'=>'9%')));
$groups = $this->Group->find('all', array('conditions'=>$conditions, 'fields'=>$fields));
break;
case 'genre':
// select by genre id
$sql = 'select groups.id, groups.prefix, groups.name, groups.votes, groups.views from groups, genre_groups where ';
$sql .= ' groups.id = genre_groups.group_id and genre_groups.genre_id ='.$action_var.' order by groups.name';
$temp = $this->Group->query($sql);
$i = 0;
$groups = array();
foreach($temp as $row)
{
$groups[$i]['Group'] = $temp[$i]['groups'];
$i++;
}
break;
}
// get the genres
$fields = array('id', 'genre');
$genres = $this->Genre->find('all', array('fields'=>$fields, 'order'=>'Genre.genre'));
$this->set('genres', $genres);
// remember what the selection page is
$this->Session->write('selection_link', SITE_HREF.'/groups/select/'.$action.'/'.$action_var);
$this->set('groups', $groups);
}
public function display($id = null, $page = null)
{
if($id == 'images'){$this->redirect(SITE_HREF.'/groups');}
$voted = false;
$count_view = true;
$comment_errors = array();
if($id == null)
{
$this->redirect(SITE_HREF.'/groups');
}
elseif(isset($this->data['Group']['option_id']))
{
// check if previously voted
$group_vote_limiter = LIMIT_VOTES.$id;
if(!$this->Session->check($group_vote_limiter))
{
// get the votes
$fields = array('votes');
$conditions = array('id'=>$this->data['Group']['option_id']);
$options = $this->Option->find('all', array('conditions'=>$conditions, 'fields'=>$fields));
if(count($options) > 0)
{
// increment the votes in the Option list for this group
$votes = $options[0]['Option']['votes'] + 1;
$this->Option->id = $this->data['Group']['option_id'];
$this->Option->saveField('votes', $votes);
}
// prevent further voting
$this->Session->write($group_vote_limiter, 1);
$voted = true;
}
// clear the forms
$count_view = false;
$this->data = null;
}
elseif(isset($this->data['Group']['add_comment']))
{
$error = false;
$group_comment_limiter = LIMIT_COMMENTS.$id;
if(!$this->Session->check($group_comment_limiter))
{
// validate the captcha
if (array_key_exists("recaptcha_response_field", $_POST))
{
$resp = recaptcha_check_answer (PRIVATEKEY,
env("REMOTE_ADDR"),
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid)
{
# set the error code so that we can display it
$comment_errors['captcha'] = '<span class="error">incorrect response</span>';
}
else
{
if($this->add_comment($id, $this->data['Group'], $comment_errors))
{
// find the group name
$fields = array('prefix', 'name');
$cond = array('id'=>$id);
$name = $this->Group->find('all', array('conditions'=>$cond, 'fields'=>$fields));
$group_name = $name[0]['Group']['prefix'].$name[0]['Group']['name'];
// send email notification
$info = &$this->data['Group'];
$to = 'musicthatjumpedtheshark@yahoo.com';
$from = 'From:musicthatjumpedtheshark@yahoo.com';
$subject = 'new group comment for: '.$group_name;
$lf = pack('C', 13, 10);
$message = date(SQL_DATE_FORMAT);
$message .= $lf;
$message .= $info['name'];
$message .= ', ';
$message .= $info['city'];
$message .= ', ';
$message .= $info['state'];
$message .= $lf;
$message .= $lf;
$message .= $info['comment'];
mail($to, $subject, $message, $from);
// prevent further comments and clear the form
$this->Session->write($group_comment_limiter, 1);
$this->data = null;
}
}
}
}
$count_view = false;
}
// find the group info
$fields = array('id', 'prefix', 'name', 'home_page', 'views', 'votes', 'file_size');
$cond = array('id'=>$id);
$group = $this->Group->find('all', array('conditions'=>$cond, 'fields'=>$fields));
if(!array_key_exists(0, $group)){$this->redirect(SITE_HREF.'/groups');}
// get the genres
$fields = array('id', 'genre');
$genres = $this->Genre->find('all', array('fields'=>$fields, 'order'=>'Genre.genre'));
// find the top options
$fields = array('id', 'option_def', 'votes');
$conditions = array('group_id'=>$id);
$group_by = array('votes desc', 'option_def asc');
$options = $this->Option->find('all', array('conditions'=>$conditions, 'fields'=>$fields, 'group'=>$group_by));
$options['display'] = count($options);
// find the latest comments
$fields = array('comment', 'name', 'city', 'state', 'date');
$cond = array('group_id'=>$id);
$group_by = array('date desc');
$comments = $this->Comment->find('all', array('conditions'=>$cond, 'fields'=>$fields, 'group'=>$group_by));
// paginate the comments
$href = SITE_HREF.'/groups/display';
my_paginate($id, $page, count($comments), COMMENTS_PER_PAGE, $href, $info);
if($count_view)
{
// increment the view count
$views = $group[0]['Group']['views'];
$views++;
$this->Group->id = $id;
$this->Group->saveField('views', $views);
}
if($voted)
{
// increment total votes in the Group
$votes = $group[0]['Group']['votes'] + 1;
$this->Group->id = $id;
$this->Group->saveField('votes', $votes);
$group[0]['Group']['votes'] = $votes;
}
$this->set('genres', $genres);
$this->set('options', $options);
$this->set('comments', $comments);
$this->set('page_info', $info);
$this->set('group', $group);
$this->set('comment_errors', $comment_errors);
}
/**
* PRIVATE ADMINISTRATIVE PAGES
*/
public function admin()
{
$this->require_login($this->login_page);
$this->layout = 'admin';
$this->pageTitle = 'Music That Jumped the Shark ~ admin groups';
$msg = '';
$add_errors = array();
$find_errors = array();
if(isset($this->data['Group']['add_form']))
{
$gp = new handleGroup($this, $this->Group);
$gp->add($this->data['Group']);
if($gp->status)
{
// clear the form if all is well
$msg = 'Group \''.$this->data['Group']['prefix'].$this->data['Group']['name'].'\' added';
$this->data['Group'] = null;
}
else
{
$msg = 'Group not added';
}
$add_errors = $gp->errors;
}
// get the list of genres
$results = $this->Genre->find('all', array('order'=>'genre'));
$this->set('genres', $results);
$this->set('msg', $msg);
$this->set('add_errors', $add_errors);
$this->set('find_errors', $find_errors);
}
public function glist($action = null, $action_var = null)
{
$this->require_login($this->login_page);
$this->layout = 'admin';
$this->pageTitle = 'Music That Jumped the Shark ~ admin groups';
$results = array();
if(isset($this->data['Group']['find_form']))
{
$action = 'prefix';
$action_var = $this->sanitize_form_input($this->data['Group']['f_name']);
}
switch($action)
{
default:
// no action - go back to home page
$this->redirect(SITE_HREF.'/admin');
break;
case 'prefix':
// select by prefix
$fields = array('id', 'prefix', 'name', 'votes', 'views');
$conditions = array('name like '=>$action_var.'%');
$results = $this->Group->find('all', array('conditions'=>$conditions, 'fields'=>$fields));
break;
case 'digit':
// select all groups beginning with a digit
$fields = array('id', 'prefix', 'name', 'votes', 'views');
$conditions = array('OR' =>array(
array('name like'=>'0%'),
array('name like'=>'1%'),
array('name like'=>'2%'),
array('name like'=>'3%'),
array('name like'=>'4%'),
array('name like'=>'5%'),
array('name like'=>'6%'),
array('name like'=>'7%'),
array('name like'=>'8%'),
array('name like'=>'9%')));
$results = $this->Group->find('all', array('conditions'=>$conditions, 'fields'=>$fields));
break;
}
$this->set('results', $results);
$this->Session->write('glist', SITE_HREF.'/groups/glist/'.$action.'/'.$action_var);
}
public function gedit($id = null)
{
$this->require_login($this->login_page);
$this->layout = 'admin';
$this->pageTitle = 'Music That Jumped the Shark ~ admin groups';
$edit_errors = array();
if($id == null){$this->redirect('/groups/admin');}
$this->set("id", $id);
$action = 'none';
if($this->data)
{
if(isset($this->data['Group']['edit'])){$this->set('data', $this->data);$action = 'edit';}
elseif(isset($this->data['Group']['delete'])){$this->set('data', $this->data);$action = 'delete';}
}
switch($action)
{
case 'edit':
// get the existing values
$fields = array('prefix', 'name', 'home_page', 'votes', 'views');
$conditions = array('id'=>$id);
$current = $this->Group->find('all', array('conditions'=>$conditions, 'fields'=>$fields));
$gp = new handleGroup($this, $this->Group);
$gp->update($id, $this->data['Group'], $current[0]['Group']);
$edit_errors = $gp->errors;
break;
case 'delete':
// delete the record
$gp = new handleGroup($this, $this->Group);
$gp->remove($id);
if($gp->status)
{
$link = $this->Session->read('glist');
if($link)
{
$this->flash('group deleted (click to continue)', $link);
}
else
{
$this->flash('group deleted (click to continue)', '/groups/admin');
}
}
else
{
$this->flash('can\'t delete this group(click to continue)', '/groups/gedit/'.$id);
}
break;
case 'none':
default:
// do nothing
break;
}
// always display the page editing options
$fields = array('prefix', 'name', 'home_page', 'votes', 'views');
$conditions = array('id'=>$id);
$group = $this->Group->find('all', array('conditions'=>$conditions, 'fields'=>$fields));
$this->set('group', $group);
$this->set('edit_errors', $edit_errors);
}
public function ggenres($id = null)
{
$this->require_login($this->login_page);
$this->layout = 'admin';
$this->pageTitle = 'Music That Jumped the Shark ~ admin groups';
if($id == null){$this->redirect('/groups/admin');}
$this->set("id", $id);
$action = 'none';
if($this->data)
{
if(isset($this->data['Group']['gadd'])){$this->set('data', $this->data);$action = 'gadd';}
elseif(isset($this->data['Group']['gremove'])){$this->set('data', $this->data);$action = 'gremove';}
}
switch($action)
{
case 'gadd':
// add this group to the genre
$list = new modelList($this, $this->Genre, $this->GenreGroup,
'Genre', 'GenreGroup', 'genre', 'genre_id', 'group_id');
$list->add($id, $this->data['Group']['gadd']);
$this->data = null;
break;
case 'gremove':
// remove this group from the genre
$list = new modelList($this, $this->Genre, $this->GenreGroup,
'Genre', 'GenreGroup', 'genre', 'genre_id', 'group_id');
$list->remove($id, $this->data['Group']['gremove']);
break;
case 'none':
default:
// do nothing
break;
}
$fields = array('prefix', 'name', 'home_page', 'votes', 'views');
$cond = array('id'=>$id);
$group = $this->Group->find('all', array('conditions'=>$cond, 'fields'=>$fields));
$fields = array('id', 'genre');
$genres = $this->Genre->find('all', array('order'=>'Genre.genre', 'fields'=>$fields));
$sql = 'select genres.genre from genres, genre_groups where ';
$sql .= ' genres.id = genre_groups.genre_id and genre_groups.group_id ='.$id ;
$sql .= ' order by genres.genre';
$genre_groups = $this->GenreGroup->query($sql);
$this->set('group', $group);
$this->set('genres', $genres);
$this->set('genre_groups', $genre_groups);
}
public function goptions($group_id = null, $action = null, $option_id = null)
{
$this->require_login($this->login_page);
$this->layout = 'admin';
$this->pageTitle = 'Music That Jumped the Shark ~ admin groups';
$errors = array();
if($group_id == null){$this->redirect('/groups/admin');}
$this->set("id", $group_id);
$data = $this->Group->find('all', array('conditions'=>array('id'=>$group_id)), array('name'));
$this->set('group_name', $data[0]['Group']['prefix'].$data[0]['Group']['name']);
if($action == null){$action = 'none';}
switch($action)
{
case 'edit':
if($this->data['Option']['option_def'] == '')
{
$errors['edit'] = '<span class="error">option cannot be empty</span>';
$errors['edit_id'] = $option_id;
break;
}
$this->Option->id = $option_id;
$this->Option->saveField('option_def', $this->data['Option']['option_def']);
$this->Option->saveField('votes', $this->data['Option']['votes']);
$this->data = null;
break;
case 'add':
if($this->data['Option']['option_def'] == '')
{
$errors['add'] = '<span class="error">option cannot be empty</span>';
break;
}
$this->add_option($group_id, $this->data['Option']['option_def']);
$this->data = null;
break;
case 'remove':
$this->Option->remove($option_id);
break;
case 'none':
default:
// do nothing
break;
}
// find all options for this group
$fields = array('id', 'option_def', 'votes');
$cond = array('group_id'=>$group_id);
$order = array('votes desc', 'option_def asc');
$options = $this->Option->find('all', array('conditions'=>$cond, 'fields'=>$fields, 'order'=>$order));
$this->set('options', $options);
$this->set('option_errors', $errors);
}
public function gcomments($group_id = null, $action = null, $comment_id = null, $dummy = null, $page = null)
{
$this->require_login($this->login_page);
$this->layout = 'admin';
$this->pageTitle = 'Music That Jumped the Shark ~ admin groups';
$comment_errors = array();
if($group_id == null){$this->redirect('/groups/admin');}
$data = $this->Group->find('all', array('conditions'=>array('id'=>$group_id)), array('name'));
$this->set('group_name', $data[0]['Group']['prefix'].$data[0]['Group']['name']);
if($action == null){$action = 'none';}
switch($action)
{
case 'edit':
$this->Comment->id = $comment_id;
$data = array('Comment'=>array());
$data['Comment']['comment'] = $this->data['Comment']['comment'];
$data['Comment']['name'] = $this->data['Comment']['name'];
$data['Comment']['city'] = $this->data['Comment']['city'];
$data['Comment']['state'] = $this->data['Comment']['state'];
$data['Comment']['date'] = $this->data['Comment']['date'];
$this->Comment->save($data);
break;
case 'add':
$test = $this->add_comment($group_id, $this->data['Group'], $comment_errors);
if($test){$this->data = null;}
break;
case 'remove':
$this->Comment->remove($comment_id);
break;
case 'none':
default:
// do nothing
break;
}
// find all comments for this group
$fields = array('id', 'comment', 'name', 'city', 'state', 'date');
$cond = array('group_id'=>$group_id);
$group_by = array('date desc');
$comments = $this->Comment->find('all', array('conditions'=>$cond, 'fields'=>$fields, 'group'=>$group_by));
$this->set('comments', $comments);
$this->set('comment_errors', $comment_errors);
// paginate the comments
$href = SITE_HREF.'/groups/gcomments/'.$group_id.'/null/null';
my_paginate($group_id, $page, count($comments), COMMENTS_PER_PAGE, $href, $info);
$this->set('page_info', $info);
$this->set('group_id', $group_id);
}
public function gecomments($comment_id = null, $action = null, $action_var = null)
{
$this->require_login($this->login_page);
$this->layout = 'admin';
$this->pageTitle = 'Music That Jumped the Shark ~ admin groups';
$comment_errors = array();
$comment = array();
if($comment_id == null){$this->redirect('/groups/admin');}
if($action == null){$action = 'none';}
$this->Comment->id = $comment_id;
switch($action)
{
case 'name':
$this->Comment->saveField('name', $this->data['Comment']['name']);
break;
case 'city':
$this->Comment->saveField('city', $this->data['Comment']['city']);
break;
case 'state':
$this->Comment->saveField('state', $this->data['Comment']['state']);
break;
case 'date':
$test = $this->Comment->saveField('date', $this->data['Comment']['date']);
break;
case 'comment':
$this->Comment->saveField('comment', $this->data['Comment']['comment']);
break;
case 'remove':
$this->Comment->remove($comment_id);
break;
case 'none':
default:
// do nothing
break;
}
$fields = array('group_id', 'comment', 'name', 'city', 'state', 'date');
$cond = array('id'=>$comment_id);
$comment = $this->Comment->find('all', array('conditions'=>$cond, 'fields'=>$fields));
$this->set('comment_id', $comment_id);
$this->set('comment', $comment[0]['Comment']);
$this->set('comment_errors', $comment_errors);
}
/**
* PRIVATE METHODS
*/
private function add_comment($group_id, &$info, &$errors)
{
$ret = false;
$errcount = 0;
$comment = $info['comment'];
$name = $info['name'];
$city = $info['city'];
$state = $info['state'];
if($comment == '')
{
$errors['comment'] = '<span class="error">comment required</span>';
$errcount++;
}
if($name == '' || strlen($name)>40)
{
$errors['name'] = '<span class="error">name 1-40 characters required</span>';
$errcount++;
}
if($city == '' || strlen($city)>40)
{
$errors['city'] = '<span class="error">city 1-40 characters required</span>';
$errcount++;
}
if($state == '')
{
$errors['state'] = '<span class="error">state selection required</span>';
$errcount++;
}
if($errcount == 0)
{
$data = array('Comment'=>array());
$data['Comment']['group_id'] = $group_id;
$data['Comment']['comment'] = htmlentities($info['comment']);
$data['Comment']['name'] = htmlentities($name);
$data['Comment']['city'] = htmlentities($city);
$data['Comment']['state'] = $state;
$data['Comment']['date'] = date(SQL_DATE_FORMAT);
$this->Comment->save($data);
$ret = true;
}
return $ret;
}
public function add_option($group_id, $option)
{
$data = array('Option'=>array());
$data['Option']['option_def'] = $option;
$data['Option']['group_id'] = $group_id;
$this->Option->id = null;
$this->Option->save($data);
}
}
class handleGroup
{
public $status;
public $msg;
public $errors;
public $controller;
public $model;
public function __construct(&$controller, &$model)
{
$this->controller = $controller;
$this->model = $model;
$this->status = true;
$this->msg = '';
$this->errors = array();
}
public function validate(&$form_data)
{
$this->status = true;
$this->msg = '';
// name must not be empty
$name = trim($form_data['name']);
if($name == '')
{
$this->errors['name'] = $this->error_msg('group name cannot be empty');
$this->status = false;
}
else
{
$prefix = substr($name, 0,4);
if(strlen($name) > 4 && (0 == strcasecmp($prefix, 'the ')))
{
$form_data['prefix'] = $prefix;
$form_data['name'] = trim(substr($name, 4));
}
else
{
$form_data['prefix'] = '';
$form_data['name'] = $name;
}
if(!ereg('^[a-zA-Z0-9]$',$form_data['name'][0]))
{
$this->errors['name'] = $this->error_msg('group name must begin with letter or number');
$this->status = false;
}
}
// home page must be valid url
if($form_data['home_page'] != '')
{
if(strlen($form_data['home_page']) < 7)
{
$this->errors['home_page'] = $this->error_msg('home page address must begin with http://');
$this->status = false;
}
if(0 != strcasecmp(substr($form_data['home_page'], 0, 7), 'http://'))
{
$this->errors['home_page'] = $this->error_msg('home page address must begin with http://');
$this->status = false;
}
}
// file upload must be valid
$test = false;
switch($form_data['image']['error'])
{
case UPLOAD_ERR_OK:
case UPLOAD_ERR_NO_FILE:
$test = true;
break;
}
if(!$test)
{
$this->errors['image'] = $this->error_msg('could not upload image file');
$this->status = false;
}
if(!$this->status)
{
$this->msg = 'form data not valid';
}
}
public function add(&$form_data)
{
$ret = false;
$this->status = true;
$this->msg = '';
$error = '';
$this->model->id = null;
while(true)
{
$this->validate($form_data);
if(!$this->status)
{
$error = 'group not added: group save failed';
break;
}
$data = array('Group');
$data['Group']['prefix'] = $form_data['prefix'];
$data['Group']['name'] = $form_data['name'];
$data['Group']['home_page'] = $form_data['home_page'];
$data['Group']['date_added'] = date(SQL_DATE_FORMAT);
$data['Group']['last_modified'] = date(SQL_DATE_FORMAT);
$data['Group']['home_page'] = $form_data['home_page'];
$picture = &$form_data['image'];
if($picture['error'] == UPLOAD_ERR_OK)
{
// generate a unique file name
$data['Group']['file_type'] = $picture['type'];
$data['Group']['file_size'] = $picture['size'];
// do an atomic save of the image file and the group record
if(!$this->model->save($data))
{
$error = 'group not added: group save failed';
$this->controller->log("groups_controller: save_group: ".$error);
break;
}
else
{
// save the uploaded image
if(!move_uploaded_file($picture['tmp_name'], GROUP_IMAGE_DIR . $this->model->id . '.jpg'))
{
// remove the group just added
$this->model->remove();
$error = 'group not added: file upload failed';
$this->controller->log("groups_controller: move_uploaded_file: ".$error);
break;
}
}
}
elseif(!$this->model->save($data))
{ echo 'here';
$error = 'group not added: group save failed';
$this->controller->log("groups_controller: save_group: ".$error);
break;
}
// add 'Never Jumped' & 'Always Jumped' options
$group_id = $this->model->id;
$this->controller->add_option($group_id, 'Music that NEVER Jumped the Shark');
$this->controller->add_option($group_id, 'Music that ALWAYS Jumped the Shark');
if($form_data['option'] != '')
{
// add the user's option
$option = trim($form_data['option']);
$this->controller->add_option($group_id, $option);
}
if($form_data['genre'] > 0)
{
// add the user's genre
$genre = trim($form_data['genre']);
$list = new modelList($this, $this->controller->Genre, $this->controller->GenreGroup,
'Genre', 'GenreGroup', 'genre', 'genre_id', 'group_id');
$list->add($group_id, $genre);
}
$this->data = null;
$ret = true;
break;
}
$this->status = $ret;
$this->msg = $error;
return $ret;
}
public function update($id, &$new, &$old)
{
// get the
$data = array('Group');
$changed = false;
while(true)
{
$this->validate($new);
if(!$this->status)
{
break;
}
// compare new and old fields
if($old['prefix'] != $new['prefix'])
{
$data['Group']['prefix'] = $new['prefix'];
$changed = true;
}
if($old['name'] != $new['name'])
{
$data['Group']['name'] = $new['name'];
$changed = true;
}
if($old['home_page'] != $new['home_page'])
{
$data['Group']['home_page'] = $new['home_page'];
$changed = true;
}
if($old['votes'] != $new['votes'])
{
$data['Group']['votes'] = $new['votes'];
$changed = true;
}
if($old['views'] != $new['views'])
{
$data['Group']['views'] = $new['views'];
$changed = true;
}
if($new['image']['error'] == UPLOAD_ERR_OK)
{
// swap out the new and old image files
move_uploaded_file($new['image']['tmp_name'], GROUP_IMAGE_DIR.$id.'.jpg');
$data['Group']['file_size'] = $new['image']['size'];
$data['Group']['file_type'] = $new['image']['type'];
$changed = true;
}
if($changed)
{
// update the record
$data['Group']['last_modified'] = date(SQL_DATE_FORMAT);
$this->model->id = $id;
$this->model->save($data);
}
break;
}
}
public function remove($id)
{
$this->status = true;
$ctrl = $this->controller;
$fields = array('id');
$conditions = array('group_id'=>$id);
// delete all options
$model = $ctrl->Option;
$temp = $model->find('all', array('conditions'=>$conditions, 'fields'=>$fields));
foreach($temp as $row)
{
$model->remove($row['Option']);
}
// delete all comments
$model = $ctrl->Comment;
$temp = $model->find('all', array('conditions'=>$conditions, 'fields'=>$fields));
foreach($temp as $row)
{
$model->remove($row['Comment']);
}
// delete all genre
$model = $ctrl->GenreGroup;
$temp = $model->find('all', array('conditions'=>$conditions, 'fields'=>$fields));
foreach($temp as $row)
{
$model->remove($row['GenreGroup']);
}
// delete the group
$fields = array('file_size');
$conditions = array('id'=>$id);
$temp = $this->model->find('all', array('conditions'=>$conditions, 'fields'=>$fields));
$this->model->remove($id);
// delete the group image
if($temp[0]['Group']['file_size'] != null)
{
$temp = unlink(GROUP_IMAGE_DIR.$id.'.jpg');
}
}
private function error_msg($string)
{
return '<span class="error">'.$string.'</span>';
}
}
class modelList
{
// examples
public $obj; // &$this
public $model_obj; // &$this->Genre
public $list_obj; // &$this->GenreGroup
public $model; // 'Genre'
public $model_list; // 'GenreGroup'
public $model_name; // 'genre'
public $model_id; // 'genre_id'
public $group_id; // 'group_id'
public function __construct(&$obj, &$model_obj, &$list_obj, $model, $model_list, $model_name, $model_id, $group_id)
{
$this->obj = $obj;
$this->model_obj = $model_obj;
$this->list_obj = $list_obj;
$this->model = $model;
$this->model_list = $model_list;
$this->model_name = $model_name;
$this->model_id = $model_id;
$this->group_id = $group_id;
}
public function add($group_id, $model_id)
{
$ret = false;
while(true)
{
// add model_id to the group
$data = array($this->model_list => array());
$data[$this->model_list][$this->model_id] = $model_id;
$data[$this->model_list][$this->group_id] = $group_id;
$this->list_obj->id = null;
if(!$this->list_obj->save($data))
{
$this->obj->log('add: could not save group_id['.$group_id.'], model_id['.$model_id.']');
break;
}
break;
}
return $ret;
}
public function remove($id, $name)
{
$ret = false;
while(true)
{
// find the genre id
$result = $this->model_obj->find('all', array('conditions'=>array($this->model_name=>$name)));
if(count($result) != 1)
{
$this->obj->log('remove: could not find model_name \''.$genre.'\'');
break;
}
// find the genre_groups id
$data = array($this->model_list => array());
$data[$this->model_list][$this->model_id] = $result[0][$this->model]['id'];
$data[$this->model_list][$this->group_id] = $id;
$result = $this->list_obj->find('all',
array('conditions'=>array($this->model_id=>$result[0][$this->model]['id'], $this->group_id=>$id)));
if(count($result) != 1)
{
$this->obj->log('remove: could not find list id \''.$name.'\'');
break;
}
// remove genre to the group
if(!$this->list_obj->remove($result[0][$this->model_list]['id']))
{
$this->obj->log('remove: could not remove list id \''.$result[0][$this->model_list]['id'].'\'');
break;
}
break;
}
return $ret;
}
}
default.ctp:
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title><?php echo $title_for_layout; ?></title>
<?php ($this->Html->css('shark')); ?>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="bands, music, community, shark, jump the shark, music that jumped the shark, sporting events, advertisement, ad, ads, success, advertise, advertise with us, jumping, video, music video, media, rich media, favorite, favorite music, review, music review, ">
<meta name="description" content=" Voice your discontent on all music! When did your favorite artist jump the shark?">
<meta content="Jump the Shark, Music, Climax" name="keywords">
</head>
<body bgcolor="#1355B5" background="/images/blestripbg.gif" style="background-attachment: fixed">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="900">
<tr>
<td colspan="3">
<?php ($this->Html->image('index_01.jpg'));?></td>
</tr>
<tr>
<td width="182">
<?php ($this->Html->image('index_02.jpg'));?></td>
<td width="324">
<td width="12">
<?php ($this->Html->image('index_04.jpg'));?></td>
</tr>
<tr>
<td width="900" colspan="3">
<?php ($this->Html->image('index_05.jpg'));?></td>
</tr>
<tr>
<td class="top-nav-bar" width="900" height="28" colspan="3">
<b>
<?php echo $this->Html->link('<span class="c1">Home</span>', '/groups/index', array('class' => 'c2'), null, false)?>
|
<?php echo $this->Html->link('<span class="c1">Blog</span>', '/blogs', array('class' => 'c2'), null, false)?>
|
<?php echo $this->Html->link('<span class="c1">FAQs</span>', '/pages/faq', array('class' => 'c2'), null, false)?>
|
<?php echo $this->Html->link('<span class="c1">Advertise</span>', '/pages/adv', array('class' => 'c2'), null, false)?>
|
<?php echo $this->Html->link('<span class="c1">Links</span>', '/pages/links', array('class' => 'c2'), null, false)?>
</b>
</td>
<!--
<td width="518" colspan="3" style="background-image: url('/images/menu_title.jpg'); background-repeat: repeat-x; background-position: left center" height="28">
<b><font face="Arial" size="2" color="#282828">
<a href="index.html" style="text-decoration: none">
<font color="#000000">Home</font></a> |
<a href="faqs.html" style="text-decoration: none">
<font color="#000000">FAQs </font></a> </font></b></td>
-->
</tr>
</table>
<div align="center">
<table id="table2" cellpadding="0" cellspacing="0" >
<!-- ROW 1 horizontal white space
<tr>
<td bgcolor="#FFFFFF" width="900" height="10" colspan="7"> </td>
</tr>
-->
<!-- ROW 2 content -->
<!-- -->
<!-- DYNAMIC CONTENT HERE -->
<?php echo $content_for_layout; ?>
<!-- -->
<!-- -->
<!-- ROW 3 white space
<tr>
<td bgcolor="#FFFFFF" width="618" colspan="7" height="19"> </td>
</tr>
-->
<!-- ROW 4 footer navigation menu -->
</table>
</div>
<div align="center">
<table id="table2" cellpadding="0" cellspacing="0" >
<tr>
<td class="lower-nav-bar" width="900" height="28">
<span style="line-height:27px">
<a href="/groups/index" style="text-decoration: none"><font color="#000000">Home</font></a>
|
<a href="/blogs" style="text-decoration: none">
<font color="#000000">Blog</font></a>
|
<a href="/pages/faq" style="text-decoration: none">
<font color="#000000">FAQs</font></a>
|
<a href="/pages/adv" style="text-decoration: none">
<font color="#000000">Advertise</font></a>
|
<a href="/pages/links" style="text-decoration: none">
<font color="#000000">Links</font></a>
|
<a href="http://www.couplescorner.biz" style="text-decoration: none">
<font color="#000000">Couple's Corner</font></a>
|
</span>
</td>
</tr>
</table>
</div>
</div>
<p align="center">
<font face="Arial" size="2">
<b>Website Developed by Sky Limited Inc. Copyright 2006<font color="#000000"></font></a>
| <a href="/admins/login">Administrator</font></a>
</font>
</p>
</body>
</html>
On Saturday, August 23, 2014 5:47:08 PM UTC-4, Dallas wrote:
does anyone know how this should be<?php e($html->image('index_01.jpg'));?></td> and<?php e($html->css('shark')); ?>shark being my stylesheet. when I removed the above css line, my background came up. So I do not know if I no longer need these lines or if the language has changed. They were calling for undefined functions in the error messages.Thanks for any help
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment