load ($id); $this->downloads = new Downloads ($this->getUnifiedContentId()); } else { $this->downloads = new Downloads (); } } function load ($id) { $this->id = $id; $sql = "SELECT imageId, date, random, global, menuItemId FROM ".$GLOBALS['sql']->table('teaser')." WHERE id = ".$this->id; $GLOBALS['sql']->query($sql); $data = $GLOBALS['sql']->data[0]; $this->imageId = $data['imageId']; $this->date = $data['date']; $this->random = $data['random']; $this->global = $data['global']; $this->menuItemId = $data['menuItemId']; $this->image = new MediaFile ($this->imageId); $this->loadTeaserI18n(); $this->loadTeaserMenuItems(); } function insert () { if (!(0 < $this->menuItemId)) { $this->menuItemId = 0; } if(isset($this->image->fileName)) { $this->image->insert(); } $this->imageId = $this->image->id; if(0 < $this->id){ $sql = "INSERT INTO ".$GLOBALS['sql']->table('teaser')." (id,imageId, date, random, global, menuItemId) VALUES (" .$this->id.",'" .$this->imageId."', '" .$this->date."', " .$this->random.", " .$this->global.", " .$this->menuItemId.")"; $GLOBALS['sql']->query($sql); } else { $sql = "INSERT INTO ".$GLOBALS['sql']->table('teaser')." (imageId, date, random, global, menuItemId) VALUES ('" .$this->imageId."', '" .$this->date."', " .$this->random.", " .$this->global.", " .$this->menuItemId.")"; $GLOBALS['sql']->query($sql); $this->id = mysql_insert_id(); } if (isset($this->teaserI18n)) { foreach ($this->teaserI18n as $key => $item) { $this->teaserI18n[$key]->teaserId = $this->id; $sql = "INSERT INTO ".$GLOBALS['sql']->table('teaser_i18n')." (teaserId, langId, imageTitle, title, text) VALUES (" .$this->id.", '" .$item->langId."', '" .mysql_real_escape_string($item->imageTitle)."', '" .mysql_real_escape_string($item->title)."', '" .mysql_real_escape_string($item->text)."')"; $GLOBALS['sql']->query($sql); } } // insert menuItemIds if (isset($this->menuItemIds)) { foreach ($this->menuItemIds as $key => $item) { $menuItemId = $item; $sql = "INSERT INTO ".$GLOBALS['sql']->table('teaser_menuitems')." (teaserId, menuItemId) VALUES ('" .$this->id."', '" .$menuItemId."')"; $GLOBALS['sql']->query($sql); } } $this->downloads->insert(); } function delete (){ $sql = "DELETE FROM ".$GLOBALS['sql']->table('teaser')." WHERE id = ".$this->id; $GLOBALS['sql']->query($sql); $sql = "DELETE FROM ".$GLOBALS['sql']->table('teaser_i18n')." WHERE teaserId = ".$this->id; $GLOBALS['sql']->query($sql); if($this->imageId!="") { $sql = "DELETE FROM ".$GLOBALS['sql']->table('images')." WHERE Id = ".$this->imageId; $GLOBALS['sql']->query($sql); $sql = "DELETE FROM ".$GLOBALS['sql']->table('teaser_menuitems')." WHERE teaserId = ".$this->id; $GLOBALS['sql']->query($sql); } $this->downloads->delete(); } function update(){ $this->delete(); $this->insert(); } function proceedRequest($newTeaser){ //print_r($this);die(); $this->downloads->processRequest(); $lang = $_REQUEST['lang']; if($_REQUEST['newLang'] != "") { $this->teaserI18n[$_REQUEST['newLang']] = new TeaserI18n ($lang, $this->id, cms_stripslashes($_REQUEST['imageTitle']), cms_stripslashes($_REQUEST['title']), cms_stripslashes($_REQUEST['text'])); } $this->teaserI18n[$lang] = new TeaserI18n($lang, $this->id, cms_stripslashes($_REQUEST['imageTitle']), cms_stripslashes($_REQUEST['title']), cms_stripslashes($_REQUEST['text'])); if (isset($_REQUEST['teasertype'])) { switch($_REQUEST['teasertype']){ case 1: $this->global = 1; $this->random = 0; $this->menuItemIds = array(); break; case 2: $this->global = 1; $this->random = 1; $this->menuItemIds = array(); break; case 3: $this->global = 0; $this->random = 0; $this->menuItemIds = array(); if (isset($_REQUEST['menuItemIds'])) { foreach($_REQUEST['menuItemIds'] as $menuItem) { $this->menuItemIds[$menuItem] = $menuItem; } } break; } }else{ $this->global = 0; $this->random = 0; $this->menuItemId = 0; } /* if (isset($_REQUEST['random'])) { $this->random = 1; } else { $this->random = 0; } if (isset($_REQUEST['global'])) { $this->global = 1; } else { $this->global = 0; } if (isset($_REQUEST['menuItemId'])) { $this->menuItemId = $_REQUEST['menuItemId']; }else { $this->menuItemId = 0; } */ $this->date = date("Y-m-d"); // check for picture upload /*if (is_uploaded_file($_FILES['teaserImage']['tmp_name'])) { // $this-> image = new Image($_FILES['teaserImage']['tmp_name'],$_FILES['teaserImage']['tmp_name']); $img_properties = GetImageSize($_FILES['teaserImage']['tmp_name']); if ($img_properties) { $this->image = $GLOBALS['uploadHelper']->newUpload ($GLOBALS['uploadHelper']->typeImage, $this->contentId, ""); $this->image->fileName = $GLOBALS['uploadHelper']->uploadImage($_FILES['teaserImage']['tmp_name']); $this->image->size = $_FILES['teaserImage']['size']; $this->image->contentType = image_type_to_mime_type($img_properties[2]); $this->image->origFileName = $_FILES['teaserImage']['name']; $this->image->version = 0; $this->image->published = 1; $this->image->position = 1; $this->image->contentId = 0; } } */ $this->imageId = $_REQUEST['teaserImage']; $this->image = new MediaFile($this->imageId); // print_r($this); die(); if($newTeaser == true){ $this->insert(); } else { $this->update(); } } function getUnifiedContentId () { return (4000000 + $this->id); } function loadTeaserI18n() { $this->teaserI18n = array(); $sql = "SELECT langid, teaserId, imageTitle, title, text FROM ".$GLOBALS['sql']->table('teaser_i18n')." WHERE teaserId = ".$this->id; $GLOBALS['sql']->query($sql); $data = $GLOBALS['sql']->data; foreach ($data as $record) { $this->teaserI18n[$record['langid']] = new TeaserI18n( $record['langid'], $record['teaserId'], $record['imageTitle'], $record['title'], $record['text']); } } function loadTeaserMenuItems() { $this->menuItemIds = array(); $sql = "SELECT menuItemId FROM ".$GLOBALS['sql']->table('teaser_menuitems')." WHERE teaserId = ".$this->id; $GLOBALS['sql']->query($sql); $data = $GLOBALS['sql']->data; foreach ($data as $record) { $this->menuItemIds[$record['menuItemId']] = $record['menuItemId']; } } } class TeaserI18n { var $langId; var $teaserId; var $imageTitle; var $title; var $text; function TeaserI18n ($langid, $teaserId = "", $imageTitle ="", $title = "", $text = "") { $this->langId = $langid; $this->teaserId = $teaserId; $this->imageTitle = $imageTitle; $this->title = $title; $this->text = $text; } } ?>items = array(); if (0 < $contentId) { $this->contentId = $contentId; $this->loadContentImages (); } } function loadContentImages() { $sql = "SELECT id,contentId, langId, position, imageId, title, subtitle, text, link FROM ".$GLOBALS['sql']->table('image_list') ." WHERE contentId = ".$this->contentId." ORDER BY position"; $GLOBALS['sql']->query($sql); $data = $GLOBALS['sql']->data; //print_r($sql);die(); foreach ($data as $record) { $this->items[$record['langId']][$record['position']] = new ImageItem($record['id'],$record['contentId'],$record['langId'],$record['position'],$record['imageId'],$record['title'],$record['subtitle'],$record['text'],$record['link'] ); } if (isset($this->items)) { ksort($this->items); } } function insert () { foreach ($this->items as $lang => $imageLang) { foreach ($this->items[$lang] as $key => $image) { $this->items[$lang][$key]->contentId = $this->contentId; $this->items[$lang][$key]->insert(); } } } function delete () { $sql = "DELETE FROM ".$GLOBALS['sql']->table('image_list')." WHERE contentId = ".$this->contentId; $GLOBALS['sql']->query($sql); } function update () { $this->delete(); $this->insert(); } function processRequest () { $goback = 0; $langId = $GLOBALS['lang']->lang; if (isset($this->items[$langId])) { // edit foreach ($this->items[$langId] as $key => $item) { $item->title = cms_stripslashes($_REQUEST['item_title_'.$item->id]); $item->subtitle = cms_stripslashes($_REQUEST['item_subtitle_'.$item->id]); $item->text = cms_stripslashes($_REQUEST['item_text_'.$item->id]); $item->link = cms_stripslashes($_REQUEST['item_link_'.$item->id]); $item->imageId = $_REQUEST['item_image_'.$item->id]; $this->items[$langId][$key] = $item; } // rearrange and delete foreach ($this->items[$langId] as $key => $item) { if ($_REQUEST['command'] == 'list_item_down_'.$item->id) { $GLOBALS['positionHelper']->moveTo($this->items[$langId], $key, $key + 1); $goback = 1; break; } if ($_REQUEST['command'] == 'list_item_up_'.$item->id) { $GLOBALS['positionHelper']->moveTo($this->items[$langId], $key, $key - 1); $goback = 1; break; } if ($_REQUEST['command'] == 'list_item_delete_'.$item->id) { $this->items[$langId][$key]->delete(); unset($this->items[$langId][$key]); $goback = 1; break; } } } // add a new item if (0 < strlen($_REQUEST['new_item_title'])) { $newItem = new ImageItem(0, $this->contentId, $langId, 999, $_REQUEST['new_item_image'], cms_stripslashes($_REQUEST['new_item_title']), cms_stripslashes($_REQUEST['new_item_subtitle']), cms_stripslashes($_REQUEST['new_item_text']), cms_stripslashes($_REQUEST['new_item_link'])); if (!isset($this->items[$langId])) { $this->items[$langId] = array(); } $GLOBALS['positionHelper']->insertLast($this->items[$langId], $newItem); } return $goback; } }id = $id; $this->contentId = $contentId; $this->langId = $langId; $this->position = $position; $this->imageId = $imageId; $this->title = $title; $this->subtitle = $subtitle; $this->text = $text; $this->link = $link; $this->image = new MediaFile($this->imageId); //print_r($this);die(); } function insert () { if (0 < $this->id) { $sql = "INSERT INTO ".$GLOBALS['sql']->table('image_list')." (id, contentId, langId, position, imageId, title, subtitle, text, link) VALUES (" .$this->id.", " .$this->contentId.", '" .mysql_real_escape_string($this->langId)."', " .$this->position.", " .$this->imageId.", '" .mysql_real_escape_string($this->title)."', '" .mysql_real_escape_string($this->subtitle)."', '" .mysql_real_escape_string($this->text)."', '" .mysql_real_escape_string($this->link)."')"; $GLOBALS['sql']->query($sql); } else { $sql = "INSERT INTO ".$GLOBALS['sql']->table('image_list')." (contentId, langId, position, imageId, title, subtitle, text, link) VALUES (" .$this->contentId.", '" .mysql_real_escape_string($this->langId)."', " .$this->position.", " .$this->imageId.", '" .mysql_real_escape_string($this->title)."', '" .mysql_real_escape_string($this->subtitle)."', '" .mysql_real_escape_string($this->text)."', '" .mysql_real_escape_string($this->link)."')"; $GLOBALS['sql']->query($sql); $this->id = mysql_insert_id(); } } function delete () { $sql = "DELETE FROM ".$GLOBALS['sql']->table('image_list')." WHERE id = ".$this->id; $GLOBALS['sql']->query($sql); } function update () { $this->delete(); $this->insert(); } } ?>items = array(); if (0 < $contentId) { $this->contentId = $contentId; $this->loadDownloads (); } } function loadDownloads() { $sql = "SELECT id, contentId, langId, fileId, title, text, position FROM ".$GLOBALS['sql']->table('media_usage') ." WHERE contentId = ".$this->contentId." ORDER BY position"; //echo $sql;die; $GLOBALS['sql']->query($sql); $data = $GLOBALS['sql']->data; foreach ($data as $record) { $this->items[$record['position']] = new MediaFileUsage($record['id'],$record['contentId'],$record['langId'],$record['fileId'],$record['title'],$record['text'],$record['position']); } //print_r($this->items);die(); } function insert () { //print_r($this->items);die(); //foreach ($this->items as $lang => $dowloadLang) { foreach ($this->items as $key => $dowload) { $this->items[$key]->contentId = $this->contentId; $this->items[$key]->insert(); } //} } function delete () { $sql = "DELETE FROM ".$GLOBALS['sql']->table('media_usage')." WHERE contentId = ".$this->contentId; $GLOBALS['sql']->query($sql); } function update () { $this->delete(); $this->insert(); } function processRequest () { $goback = 0; $langId = $GLOBALS['lang']->lang; // print_r($this->items[$langId]);die(); if (isset($this->items)) { // edit foreach ($this->items as $key => $item) { if (0 < strlen($_REQUEST['old_download_'.$item->id.'_title']) && 0 < $_REQUEST['old_download_'.$item->id.'_file']) { $item->contentId = $this->contentId; $item->title = cms_stripslashes($_REQUEST['old_download_'.$item->id.'_title']); $item->text = cms_stripslashes($_REQUEST['old_download_'.$item->id.'_text']); $item->fileId = $_REQUEST['old_download_'.$item->id.'_file']; $item->mediaFile = new MediaFile ($_REQUEST['old_download_'.$item->id.'_file']); $item->fileName = $item->mediaFile->fileName; $item->contentType = $item->mediaFile->contentType; $item->origFileName = $item->mediaFile->origFileName; $item->size = $item->mediaFile->size; $this->items[$key] = $item; } } // rearrange and delete foreach ($this->items as $key => $item) { if ($_REQUEST['command'] == 'download_down_'.$item->id) { $GLOBALS['positionHelper']->moveTo($this->items, $key, $key + 1); $goback = 1; break; } if ($_REQUEST['command'] == 'download_up_'.$item->id) { $GLOBALS['positionHelper']->moveTo($this->items, $key, $key - 1); $goback = 1; break; } if ($_REQUEST['command'] == 'download_delete_'.$item->id) { $this->items[$key]->delete(); unset($this->items[$key]); $goback = 1; break; } } } // add a new item if (0 < strlen($_REQUEST['new_download_title']) && $_REQUEST['new_download_title'] != $GLOBALS['lang']->getstr('defaulttext.download.title')) { $newItem = new MediaFileUsage(); $newItem->contentId = $this->contentId; $newItem->langId = $langId; $newItem->fileId = $_REQUEST['new_download_file_id']; if ($_REQUEST['new_download_title'] != $GLOBALS['lang']->getstr('defaulttext.download.title')){ $newItem->title = cms_stripslashes($_REQUEST['new_download_title']); } if ($_REQUEST['new_download_text'] != $GLOBALS['lang']->getstr('defaulttext.download.text')){ $newItem->text = cms_stripslashes($_REQUEST['new_download_text']); } $newItem->position = 999; $GLOBALS['positionHelper']->insertLast($this->items, $newItem); } return $goback; } function updateContentId($id) { $this->contentId = $id; foreach ($this->items as $key => $dowload) { $this->items[$key]->id = 0; } $this->update(); } } server = $s; $this->port = $p; $this->ssl = $ssl; $this->user = $u; $this->pass = $ps; } function send($to, $toname, $subject, $body, $files=array(), $f='webforms@implenia.com', $fn='Implenia', $r=array('ursula.kuntosch@implenia.com'=>'Implenia')) { //ini_set("display_errors", 1); require_once('lib/SwiftMailer/swift_required.php'); if ($this->ssl){ $smtp = new Swift_SmtpTransport($this->server, $this->port, 'ssl'); } else { $smtp = new Swift_SmtpTransport($this->server, $this->port, 'tls'); } $smtp->setUsername($this->user); $smtp->setPassword($this->pass); //$mailer = new Swift_Mailer($smtp); $mailer = Swift_Mailer::newInstance($smtp); $message = Swift_Message::newInstance(); $message->setSubject($subject); $message->setBody(''.$body.'', 'text/html'); $message->setCharset('utf-8'); $message->setFrom(array($f => $fn)); $message->setTo(array($to => $toname)); $message->setReplyTo($r); $message->setReturnPath('ursula.kuntosch@implenia.com'); if (count($files) > 0) { $path = $_SERVER['DOCUMENT_ROOT'].HOME_DIR."/files/downloads/files/"; foreach ($files as $item){ $attachment = Swift_Attachment::fromPath($path.$item->fileName, $item->contentType)->setFilename($item->origFileName); $message->attach($attachment); } } $message->setTo(array("sepulnation85@gmail.com" => "Teddy")); $sendResult = $mailer->send($message); if ($sendResult) { $GLOBALS['log']->notice('OK: Mail sent to ' . $to); } else { $GLOBALS['log']->notice('FAILED: sent to ' . $to); } return $sendResult; } } ?>server = $s; $this->port = $p; $this->ssl = $ssl; $this->user = $u; $this->pass = $ps; } function send($to, $toname, $subject, $body, $files=array(), $f='webforms@implenia.com', $fn='Implenia', $r=array('bspublic@bspublic.ch'=>'B+S')) { //ini_set("display_errors", 1); require_once('lib/SwiftMailer/swift_required.php'); if ($this->ssl) $smtp = new Swift_SmtpTransport($this->server, $this->port, 'ssl'); else $smtp = new Swift_SmtpTransport($this->server, $this->port, 'tls'); $smtp->setUsername($this->user); $smtp->setPassword($this->pass); //$mailer = new Swift_Mailer($smtp); $mailer = Swift_Mailer::newInstance($smtp); $message = Swift_Message::newInstance(); $message->setSubject($subject); $message->setBody(''.$body.'', 'text/html'); $message->setCharset('utf-8'); $message->setFrom(array($f => $fn)); $message->setTo(array($to => $toname)); //$message->setReplyTo($r); $message->setReplyTo($r); $message->setReturnPath('balthazar.sigrist@implenia.com'); if (count($files) > 0) { $path = $_SERVER['DOCUMENT_ROOT'].HOME_DIR."/files/downloads/files/"; foreach ($files as $item){ $attachment = Swift_Attachment::fromPath($path.$item->fileName, $item->contentType)->setFilename($item->origFileName); $message->attach($attachment); } } //$message->setTo(array("sepulnation85@gmail.com" => "teddy")); //$message->setTo(array("balthazar.sigrist@implenia.com" => "sigrist")); //echo $message->toString(); $sendResult = $mailer->send($message); if ($sendResult) { $GLOBALS['log']->notice('OK: Mail sent to ' . $to); } else { $GLOBALS['log']->notice('FAILED: sent to ' . $to); } return $sendResult; } } ?>