setProperty('Featureiframe', $this->defaultURL); $this->setProperty('FeatureURL', $this->defaultURL); } function getUploadPath($isTmp){ if ($isTmp){ return $DOCUMENTROOT . $this->TEMP_UPLOAD . "/"; } return $DOCUMENTROOT . $this->UPLOAD_URI . "/"; } function getErrorMessages(){ return $this->errorArray; } function dataToObject($data){ reset($data); while (list($key, $value) = each($data)){ $this->setProperty($key, $value); if (!strcmp($key, 'Date')){ $date = explode( "-", $value); $this->setProperty("year", $date[0]); $this->setProperty("month", $date[1]); $this->setProperty("day", $date[2]); } } } function formToObject(){ reset($_POST); while (list($key, $value) = each($_POST)){ $this->setProperty($key, stripslashes(trim($value))); } reset($_FILES); while (list($key, $value) = each($_FILES)){ $this->setProperty($key, $_FILES[$key]); } } function addToDB($tableName){ $db = new DB_Class(); $sql = "INSERT INTO ". $tableName . " ("; $lastProp = end($this->properties); reset($this->properties); $count = 0; while (list($key, $value) = each($this->properties)){ if (strcmp($key, "month") && strcmp($key, "day") && strcmp($key, "year") && strcmp($key, "Submit")&& strcmp($key, "PreviewSubmit")){ if ($count > 0){ $sql .= " , "; $sqlValue .= " , "; } $sqlValue .= "'" . db_prepare($value) . "'"; $sql .= $key; $count ++; } if (!strcmp($value, $lastProp)){ $sql .=" ) "; $sqlValue .=" ) "; } } $sql .= " VALUES ( " . $sqlValue; return $db->query($sql); } function updateDB($tableName, $contentID){ $db = new DB_Class(); $sql = "UPDATE ". $tableName . " SET "; $lastProp = end($this->properties); $count = 0; reset($this->properties); while (list($key, $value) = each($this->properties)){ if(strcmp($key, 'featureID') && strcmp($key, "month") && strcmp($key, "day") && strcmp($key, "year") && strcmp($key, "Submit") && strcmp($key, "PreviewSubmit") && strcmp($key, "contentID")){ if ($count > 0){ $sql .= " , "; } $sql .= $key . " = '" . db_prepare($value) . "'"; $count ++; } } $sql .= " WHERE featureID= '" . $contentID . "'"; return $sql; } function removeFromDB($tableName, $contentID){ $db = new DB_Class(); $sql = "SELECT Thumbnail FROM $tableName WHERE featureID = '". $contentID . "' LIMIT 1"; $Thumbnail = $db->fetch($sql); unlink($Thumbnail[0][Thumbnail]); $sql = "SELECT Title FROM $tableName WHERE featureID = '". $contentID . "' LIMIT 1"; $Title = $db->fetch($sql); unlink($Title[0][Title]); $sql = "DELETE FROM " . $tableName . " WHERE featureID = '" . $contentID . "'"; return $db->query($sql); } function validateForm($isTmp){ $this->errorArray = Array(); $month = $this->getProperty("month"); $day = $this->getProperty("day"); $year = $this->getProperty("year"); if ( $month == "" || $day == "" | $year == ""){ $this->errorArray["Date"] = "Please enter the date."; }else{ $this->setProperty("Date", $year . "-" . $month . "-" . $day); } reset($this->properties); while (list($key, $value) = each($this->properties)){ if (strcmp($key, "month") && strcmp($key, "day") && strcmp($key, "year") && strcmp($key, "Date") && strcmp($key, "Thumbnail" ) && strcmp($key, "Title")){ if ($value == "" ){ $this->errorArray[$key] = "Please enter " . $key . "."; } } } $thumbnail = $this->getProperty("Thumbnail"); if ($thumbnail['name'] == ""){ $this->errorArray["Thumbnail"] = "Please upload a thumbnail."; }else{ if (! $this->copyAttachment($thumbnail["tmp_name"], "Thumbnail", $isTmp)){ $this->errorArray["Thumbnail"] = "Unable to upload file."; } } $title = $this->getProperty("Title"); if ($title['name'] == ""){ $this->errorArray["Title"] = "Please upload a title image."; }else{ if (! $this->copyAttachment($title["tmp_name"], "Title", $isTmp)){ $this->errorArray["Title"] = "Unable to upload file."; } } } function copyAttachment($source, $name, $isTmp){ $destPath = $this->getUploadPath($isTmp). $name . date("YmdHis") ; if (! file_exists($source)){ return 0; } $file = $this->getProperty($name); $this->setProperty($name, $destPath); return move_uploaded_file($source, $destPath); } function copyToArchive($source, $name){ $destPath = $this->getUploadPath(false). $name . date("YmdHis"); if (! file_exists($source)){ return 0; } $file = $this->getProperty($name); $this->setProperty($name, $destPath); if( !copy($source, $destPath)){ $this->errorArray["Preview"] = "Unable to move file."; }else{ return unlink($source); } } function getProperty($propertyName){ return $this->properties[$propertyName]; } function setProperty($propertyName, $propertyValue){ $this->properties[$propertyName] = $propertyValue; end($this->properties); } } ?> JHR Community -- Communauté JDH
getone("SELECT COUNT(*) FROM $featureTable"); $data = $db->fetch("SELECT * FROM $featureTable ORDER BY featureID DESC LIMIT $start, $display"); foreach ($data as $row){ $feature = new Feature(); $feature->dataToObject($row); ?>