id = $params['id']; } $this->path = $params['path']; $this->name = $params['name']; if(isset($params['type'])) $this->type = $params['type']; $this->thumbnail_path = $params['thumbnail_path']; } } private function create_thumbnail() { global $web_root; global $event_path; global $event_thumbnail_path; $userfile_type = $this->type; echo $userfile_type . "= type
"; $size1 = 150; $size2 = 260; $upfile = "$web_root/$event_path/$this->path"; $size = GetImageSize($upfile); echo $upfile . "
"; $path_parts = pathinfo(basename($upfile)); $fext = $path_parts['extension']; // Wide Image if($size[0] > $size[1]) { $thumbnail_width = $size1; $thumbnail_height = (int)($size1 * $size[1] / $size[0]); } else // Tall Image { $thumbnail_width = (int)($size1 * $size[0] / $size[1]); $thumbnail_height = $size1; } $gd_function_suffix = array( 'image/pjpeg' => 'jpeg', 'image/jpeg' => 'jpeg', 'image/jpg' => 'jpg', 'image/gif' => 'gif', 'image/bmp' => 'wbmp', 'image/x-png' => 'png', 'image/png' => 'png' ); // Get the Name Suffix on basis of the mime type $function_suffix = $gd_function_suffix[$userfile_type]; // Build Function name for ImageCreateFromSUFFIX $function_to_read = 'ImageCreateFrom' . $function_suffix; // Build Function name for ImageSUFFIX $function_to_write = 'Image' . $function_suffix; $function_suffix = $gd_function_suffix[$userfile_type]; $function_to_read = 'ImageCreateFrom' . $function_suffix; echo "ICF $function_to_read
"; $function_to_write = 'Image' . $function_suffix; // Read the source file $source_handle = $function_to_read($upfile); if ($source_handle) { // Let's create a blank image for the thumbnail $destination_handle = imagecreatetruecolor($thumbnail_width, $thumbnail_height) ; if(! $destination_handle) { echo "Failed\n"; } // Now we resize it if(!ImageCopyResized($destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1])) { echo "failed 2"; } } // Let's save the thumbnail $function_to_write($destination_handle, "$web_root/$event_thumbnail_path/$this->path"); ImageDestroy($destination_handle); $this->thumbnail_path = $this->path; } public static function find_all() { $sql = "select * from events"; $events = array(); $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { $events[] = new Event($row); } return $events; } public static function find($id = null,$start) { if($id) { $sql = "SELECT * FROM events WHERE id=$id"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); return new Event($row); } else { $sql = "select * from events order by id limit $start,10"; $events = array(); $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { $events[] = new Event($row); } } return $events; } public static function find_by_id($id) { $sql = "SELECT * FROM events WHERE id=$id"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); return new Event($row); } public function save() { $this->create_thumbnail(); $sql = "INSERT INTO events(`name`,`path`,`thumbnail_path`)VALUES('$this->name','$this->path','$this->thumbnail_path')"; mysql_query($sql) or die(mysql_error()); } public function edit($id) { $this->create_thumbnail(); $sql = "UPDATE events SET `name`='$this->name', `path`='$this->path',`thumbnail_path`='$this->thumbnail_path' WHERE `id`='$id'"; mysql_query($sql) or die(mysql_error()); } public function delete() { global $web_root; global $event_path; global $event_thumbnail_path; $sql = "DELETE FROM events where id=$this->id" ; mysql_query($sql); unlink("$web_root/$event_path/$this->path"); unlink("$web_root/$event_thumbnail_path/$this->path"); } public function id() { return $this->id; } public function path() { return "$web_root/$event_path/$this->path"; } public function thumbnail_path() { return "$web_root/$event_thumbnail_path/$this->thumbnail_path"; } public function thumbnail_url() { global $event_thumbnail_path; return $event_thumbnail_path."/".$this->thumbnail_path; } public function image_url() { global $event_path; return "$event_path/$this->thumbnail_path"; } public function name() { return $this->name; } public static function Count() { $sql = "SELECT count(id) AS event_count from events"; $result = mysql_query($sql); echo mysql_error(); $row = mysql_fetch_assoc($result); return $row['event_count']; } } ?>