Skip to content

Instantly share code, notes, and snippets.

@tik9
Last active Dec 26, 2015
Embed
What would you like to do?
Homepage made of js, model, view and controller (model used seldom at the moment)
// controller
<?php
class Homepage extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('Homepage_Model');
// t.b.done Country Selection: 1. Geo-Locator, 2. User
// tutorial geo ip http://bartomedia.blogspot.de/2007/11/maxmind-geoip-setup-tutorial-using.html
// datetime object needs timezone
date_default_timezone_set ( "Europe/Berlin" );
// low image qual. path for download and ensembles/cond.
$this->lowPicPath=base_url(). 'ImagesLow/';
} // end constr.
function getImpressum(){
?>
Konzertagentur Dagmar Körner <br>
Bergstrasse 15<br>
85120 Hepberg<br>
Germany<br>
Tel.: 0049 (0) 8456 / 91 89 29 0<br>
Fax: 03222 / 9985 848
<br><br><?php lang('ImprintText') ;?>
<br>
<a href = "http://konzertagentur-koerner.de/Timo" > Content Responsible </a>
<a href='http://www.coderanch.com/forums'>
<img alt='Coderanch status' src='http://www.coderanch.com/badge.png?id=289570' width='150' height='75'/>
</a> <?php
}
function getUeberUns(){
echo lang('aboutustext') .'<br> <br>';
$empl = array ('koerner'=> array(
'Name'=> 'Dagmar Körner',
'area'=> 'Manager'),
'mang'=>array(
'Name'=>'Brigitte Mang',
'area'=>'Sales'),
'stirner'=>array(
'Name'=>'Sigrid Stirner',
'area'=>'Abwicklung')
);
// members of agency
$i=0;
foreach ($empl as $key=>$empl2){
echo '<h2>'. $empl2['Name'] . '</h2>
'. $empl2['area']. '<br><br>
<img src= "'. base_url().'images/'. $key[$i]. '" width= "100px" alt = "Pic. '. $empl2['Name'] .'"> <br> <br>';
$i++;
}
echo '<b>Kontakt:</b> 0049 (0) 8456 91 89 29 0';
}
// switch language , set session language
function switchLanguage() {
// var_dump('switch '.$this->input->post('language'));
$language = ($this->input->post('language') != "") ? $this->input->post('language') : "de";
$this->session->set_userdata('site_lang', $language);
// var_dump($this->session->userdata('site_lang'));
redirect(base_url());
}
# homepage
public function index () {
$this->load->view ('hp' );
}
function getDirigent(){
$data['conductor'][0]= new stdClass;
$data['conductor'][0]->allmus='Ian Brown';
$data['conductor'][0]->allmus_id=1;
$this->load->view('conductorHp',$data);
}
function getSolisten(){
// soloist
$this->db->select('allmus, allmus_id, instrument' );
$this->db->from('allmus' );
$this->db->join('instrument', 'allmus.instrument_id=instrument.instrument_id');
$this->db->where('online', 1);
// $this->db->where('kategorie','solist');
$this->db->where('allmus.instrument_id !=',0);
$this->db->order_by('allmus');
$oQuery = $this->db->get();
// echo $this->db->last_query();
$data['solist'] = $oQuery->result();
$this->load->view('soloistHp',$data);
}
# Homepage Bio
public function getBioH () {
$data['res'] =$this->Homepage_Model->getBioH();
# pic
// var_dump($data);
$data['pic'] = $this-> Homepage_Model -> showPics(
$data['res'] -> allmus);
$this->load->view('BioH', $data);
$this->load->view('footer');
}
# Fotos download hp
public function getDownload() {
if ($this-> session -> userdata ('user' ) == 'peru')
$dir='privatPic/';
else
$dir='ImagesHighQuality/';
$data['foto'] = $this->Homepage_Model->getFiles( $dir);
# var_dump($data);
# Low Pic Path the same for all
$data['lowQPath'] = $this->lowPicPath;
$this->load-> view('download', $data);
}
// ajax - get Musiker
function getEnsembles(){
# Groups Cat for mus
$data['cat'] = $this->Simple_Model ->get ('kategorie');
$data['picPath']= $this->lowPicPath;
$this->load->view ('ensemblesHp' , $data );
}
// ajax - get tourneen for homepage
function getTourneen(){
echo'
<link rel="stylesheet" href="'.assetExt_url().'dataTables.css" type="text/css" />
<script type = "text/javascript" src = "'.assetExt_url().'dataTablesJs.js" > </script>';
?>
<script>
$('#dtTournee').dataTable( {
// cursor inside search field
"fnInitComplete": function () {
// this.fnAdjustColumnSizing();
// $('div.dataTables_filter input').focus();
},
// sorting 1st column, "aaSorting": [[1,'asc'] ],
'bSort':false,
// omit footer
"bInfo": false,
"oLanguage": {
"sUrl": 'http://'+location.host+'/assets/DataTables_<?php echo $this->session->userdata('site_lang');?>.txt'
},
});
</script>
<?php
$result= $this->Homepage_Model->getTourneen();
// var_dump($result);
?>
<table class="display" id="dtTournee" >
<thead>
<tr>
<th> Datum</th> <th> Musiker </th>
<th> month to tour start</th>
</tr>
</thead>
<tbody>
<?php
$dateTime1= new DateTime();
// $dateTime2 = new DateTime('22.10.2013');
// $dateTime2->setTimestamp($result[$i]->tourBegin);
// var_dump($interval);
$lastYear='';
// var. new to check if new tour block - for with i nec. because we compare two neighbouring tours
for ($i=0;$i<count($result); $i++){
$new=false;
$dateTime2=new DateTime($result[$i]->tourBegin);
$interval = $dateTime1->diff($dateTime2);
$suffix = ( ($interval->m <3 and $interval->y==0) ? ' (book quickly this tour)' : '' );
echo '<tr>';
if ($result[$i]->tournee !=$result[$i-1]->tournee) { $new=true;
echo '<td>';
if (empty($lastYear)){
$lastYear= $result[$i]->year;
echo '<b>'.$lastYear.'</b><br>';
}
if ($lastYear != $result[$i]->year){
// new year
$lastYear = $result[$i]->year;
echo '<b>'.$lastYear.'</b><br>';
}
echo $result[$i]->tourBegin.'-'.$result[$i]->tourEnde.'</td>';
}else
echo '<td></td>';
echo '<td>';
if ($new==true)
echo $result[$i]->tournee.'<br>';
echo $result[$i]->allmus;
if ($result[$i]->instrument)
echo ' - '.$result[$i]->instrument;
// interval
echo '</td>
<td>';
// show months interval if tour in less than one year and interval(m)>0
if ($interval->y==0 and $new){
if ($interval->m !=0 )
echo $interval->m ;
echo $suffix. '</td>';
}
echo '</td></tr>';
}
?>
</tbody>
</table>
<?php
}
// ajax - get Konzerte for hp
function getKonzerte(){
echo'
<link rel="stylesheet" href="'.assetExt_url().'dataTables.css" type="text/css" />
<script type = "text/javascript" src = "'.assetExt_url().'dataTablesJs.js" > </script>';
?>
<?php
// add calendar plugin css
echo '<link rel="stylesheet" href="'.asset_url().'calendar.css" type="text/css" />';?>
<script>
$('#dtAuftrag').dataTable( {
// cursor inside search field
"fnInitComplete": function () {
this.fnAdjustColumnSizing();
// $('div.dataTables_filter input').focus();
},
// sorting 1st column, "aaSorting": [[1,'asc'] ],
'bSort':false,
// omit footer
"bInfo": false,
"oLanguage": {
"sUrl": 'http://'+location.host+'/assets/DataTables_<?php echo $this->session->userdata('site_lang');?>.txt'
},
});
</script>
<?php
// calendar
$prefs = array ('start_day' => 'saturday', 'month_type' => 'long',
'day_type' => 'long');
// cal cell no content are days without events, week day has th attribut
$prefs['template'] = '
{table_open}<table class="calendar">{/table_open}
{week_day_cell}
<th class="day_header">{week_day}</th>
{/week_day_cell}
{cal_cell_content}
<span class="day_listing">{day}</span>
&nbsp;&bull; {content}&nbsp;
{/cal_cell_content}
{cal_cell_content_today}
<div class="today"><span class="day_listing">{day}</span>&bull; {content}
</div>
{/cal_cell_content_today}
{cal_cell_no_content}
<span class="day_listing">{day}</span>
&nbsp;{/cal_cell_no_content}
{cal_cell_no_content_today}
<div class="today"><span class="day_listing">{day}</span></div>
{/cal_cell_no_content_today}';
$this->load->library('calendar', $prefs);
// array with this and next month
$arr= array('thisMonth'=>0, 'nextMonth'=>1);
foreach ($arr as $key=> $value) {
// reset concert
$concerts=array();
$query = $this->db->select('day(konzertdatum) as day,auftrag')->from('auftrag')->where('month(konzertdatum)','month(now())+'.$value,false)->get();
// echo $this->db->last_query();
// create concerts array, day=> concert
foreach ($query->result() as $row) {
$concerts[$row->day] = $row->auftrag;
}
// var_dump($concerts);
$calendar= $this->calendar->generate(2013, date("m",strtotime("+".$value." month")),$concerts);
// }
echo $calendar. '<br><br>';
}
// array for concert table
$result= $this->Homepage_Model->getKonzerte();
?>
<table class="display" id="dtAuftrag" >
<thead>
<tr>
<th> Datum</th><th>Ort</th> <th> Musiker </th>
<th>Tage bis zum Event </th></tr>
</thead>
<tbody>
<?php
// today - for comparison
$datetime1 = new DateTime();
// concerts array result
for ($i=0;$i<count($result); $i++){
// variable to check if next entry
$new=false;
echo '<tr>';
if ($result[$i]->auftrag !=$result[$i-1]->auftrag) {
$new=true;
echo '<td>'.$result[$i]->concertDateTime.'</td>';
}else
echo '<td></td>';
echo '<td>';
if ($new==true)
echo $result[$i]->plzort.' '.$result[$i]->Ort.'<br>'. $result[$i]->saal;
echo '</td><td>'.$result[$i]->allmus;
if ($result[$i]->instrument)
echo ' - '.$result[$i]->instrument;
echo '</td> <td>';
// concert date time
$datetime2 = new DateTime($result[$i]->konzertdatum);
// $datetime2 = new DateTime('2013-10-10 18:00');
$interval = $datetime1->diff($datetime2);
// var_dump($interval);
$suffix = ( $interval->invert ? ' (vergangen)' : '' );
$suffix2 = ( ($interval->d <5 and ! $interval->invert) ? ' (schnell Karten besorgen)' : '' );
// check if concert today
if ($interval->days ==0 and ! $interval->invert) $suffix='heute';
if ($interval->days ==0 and $interval->invert)
$suffix='gestern';
// print day interval if concert not today or yesterday
if ($new and ! $interval->days ==0)
echo $interval->format('%R%a');
if ($new)
echo $suffix.$suffix2;
echo '</td></tr>';
}
echo ' </tbody>
</table>';
?>
--Werbung--
<a href='http://www.zanox-affiliate.de/ppc/?25987753C46054512' target='_blank' >eventim.de - Startseite</a>
<?php
}
}
//--------------------------------------------------js
<script>
// define ajax path
var ajPath = 'http://' + location.host + '/index.php/Homepage/';
$(document).ready(function(){
// home button
$('#home').click(function(e) {
// reset other text
$(".container").css("display","none");
// show text already there -> css()
$("div#home").css("display","block");
// console.log('home');
});
// homepage =home
$("#home").css("display","block");
// makes the navigation work after all containers have been hidden
showViaLink($("nav a"));
function showViaLink(array){
array.each(function(i){
$(this).click(function(){
$(".container").css("display","none");
// show load string
$('#loadText').show();
// get method name without brackets()
method=$(this).text().substring(0,$(this).text().length-3);
console.log(method);
// Download Tourneen Ensembles Konzerte Dirigent Solisten
// method='Tourneen';
$.post(ajPath+'get'+method, function(res) {
$('#loadText').hide();
$('#'+lcfirst(method)).hide().html(res).fadeIn('slow');
});
});
});
}
/*listens for any navigation keypress activity
a = 97 in 'which' in keypress, in keyup=65
*/
$(document).keypress(function(e) {
// console.log(e.type+ e.target.tagName);
// not use keypress on input
if ( e.target.tagName.toLowerCase() !='input')
// key pressed, action after decision
switch(e.which) {
// user presses "a" or u
case 97:
case 117: showViaKeypress("UeberUns");
break;
// c or d
case 99:
case 100: showViaKeypress("Dirigent");
break;
// user presses the "h" key
case 191: //l
showViaKeypress('Download');
break;
case 104: showViaKeypress("Home");
break;
case 105: //i
case 73: showViaKeypress("Impressum"); //I
break;
case 101: //e
case 109: showViaKeypress("Ensembles"); //m
break;
// user presses the "s" key
case 115: showViaKeypress("Solisten");
break;
// user presses the "t" key
case 116: showViaKeypress("Tourneen");
break;
}
});
});
// shows a given element and hides all others
function showViaKeypress(method)
{
$(".container").css("display","none");
$('#loadText').show();
// method='Tourneen';
$.post(ajPath+'get'+method, function(res) {
$('#loadText').hide();
$('#'+lcfirst(method)).hide().html(res).fadeIn('slow');
});
}
function lcfirst(string) {
return string.charAt(0).toLowerCase() + string.slice(1);
}
</script>
//------------------------view
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<?php # show logged in user
# echo $this-> session -> userdata ('user');
echo '<head>
<title>'.$this->Serv.'</title>';
?>
<meta charset='utf-8'>
<link rel="shortcut icon" href="../../assets/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="../../assets/angularMenuCss.css" type="text/css">
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<?php
include_once( $_SERVER['DOCUMENT_ROOT'].'/assets/hpJs.php');
?>
</head>
<body>
<?php $arr= array('en', 'de');
foreach ($arr as $value){
echo'<form action= "'.site_url().'/Homepage/switchLanguage" method="post">';
if ($this->session->userdata('site_lang')== $value)
echo '<div style="color:red">';
echo '<button name="language" value="'.$value.'"> '.$value;
if ($this->session->userdata('site_lang')== $value)
echo '</div>';
echo '</button></form> ';
}
// var_dump('lang'.$this->session->userdata('site_lang'));
?>
<br>
<h3>Konzertagentur Körner</h3>
<button id='home'>Home</button>
<!-- Adding the ng-app declaration to initialize AngularJS -->
<div id="main" ng-app>
<!-- The navigation menu will get the value of the "active" variable as a class.
The $event.preventDefault() stops the page from jumping when a link is clicked. -->
<nav class="{{active}}" ng-click="$event.preventDefault()">
<?php $ajax=array('Ensembles','Solisten','Dirigent','Download','Konzerte','Tourneen','Impressum','UeberUns');
foreach ($ajax as $value)
echo '<a href="#" class='.$value. ' ng-click="active=\''.$value.'\'" >'.$value.' ('.
lcfirst(mb_substr($value,0,1,'utf-8')).')</a>';
?>
</nav>
<!-- ng-show will show an element if the value in the quotes is truthful,
while ng-hide does the opposite. Because the active variable is not set
initially, this will cause the first paragraph to be visible. -->
<p ng-hide="active">Bitte einen Menüpunkt auswählen</p>
<p ng-show="active"><b>{{active}}</b></p><br><br>
</div>
<div id="loadText" style="display:none" > .. loading .. </div>
<?php
// prepare divs ajax print out like "download"
foreach ($ajax as $value)
echo '<div class="container" id="'. lcfirst($value).'"> </div>';
# ----start Home -----
echo '<div id="home" class="container">';
// greeting in language
$arr=array('de'=>'Willkommen bei der Konzertagentur Körner',
'en'=> 'Welcome to the website of Konzertagentur Körner',
'es'=> 'Bienvenido',
'it'=>'Benvenuto',
'fr'=>'Bienvenue a la site du Konzertagentur Körner');
echo '<h2>'.$arr[$this->session->userdata('site_lang')].'</h2><br>'.
lang('welcomehint').'<br> <br>
</div>';
?>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
</body>
</html>
// ---------------------------model
<?php
class Homepage_Model extends CI_Model {
// get Kategorie for Ensembles
function getKategorie(){
$this->db->from('kategorie');
// exclude soloist and conductor
$this->db->where_not_in('kategorie',array('solist','dirigent'));
$this->db->order_by('kategorie_id');
$query=$this->db->get();
return $query->result();
}
function getKonzerte(){
// join with where=false
joinSuperSub('auftrag','allmus',false);
$this->db->select('konzertdatum,saal, plzort,Ort');
// get formatted concert date time
selectConcertDateTime();
// add venue and zip
$this->db->join ('saal', 'saal.saal_id = auftrag.saal_id','left');
$this->db->join ('plzort', 'saal.plzort_id = plzort.plzort_id', 'left');
$this->db->order_by('konzertdatum');
// $this->db->where ('month(konzertdatum)',10);
$this->db-> limit (8) ;
# only this year
$this->db-> where ('year(konzertdatum)', 'year(now())', false ) ;
$query= $this->db->get();
// echo $this->db->last_query();
$result=$query->result();
return $result;
}
function getTourneen(){
// tours
$this->db->select('year(tourBeginn) as year,tournee,allmus.allmus_id,allmus');
$this->db->select("DATE_FORMAT(tourBeginn, '%e.%m.%Y') as tourBegin, DATE_FORMAT(tourEnde, '%e.%M.%Y') as tourEnde", false);
// where false because list
joinSuperSub( 'tournee','allmus', false);
$this->db->order_by('tourBeginn');
$query= $this->db->get();
// echo $this->db->last_query();
return $query->result();
// var_dump($tour);
}
function getBioH(){
$this->db->select( 'bioDe,allmus' );
// $this->db->select( $this->sT.',beschreibung_de' );
$this->db->from( 'allmus' );
$this->db->where( 'allmus_id', $this->input->post('id' ));
$query = $this->db->get();
// echo $this->db->last_query();
return $query -> row () ;
}
# loading images ; in: folder
# out: array containing name, size and date
public function getFiles( $dir ) {
$Directory = opendir ( $dir);
$sizes = array('B', 'kB', 'MB'); //Einheiten-Array
while (false != ($file = readdir ($Directory)) )
{
if ($file != '.' && $file != '..')
{
$size = filesize($dir. $file);
for ($i= 0; $size > 1000 && $i < count($sizes) - 1; $i++)
$size /= 1000;
$size = str_replace('.', ',', round($size)) . ' '. $sizes[$i];
$aSize[] = $size;
$aFileName[] = $file;
$ctime = filectime($dir . $file) ;
$aDatum[] = date ("d.m.y", $ctime );
}
}
closedir($Directory);
$aReturn = array( 'Size' => $aSize,
'Filename' => $aFileName,
'Date' => $aDatum,
);
array_multisort ($aReturn, SORT_ASC);
# var_dump( $aReturn );
return $aReturn;
}
# Parameter: normal pic or high res
# Return: file and path
public function showPics($sWho) {
$such_array = array ('ä', 'ö', 'ü', 'ß', ' ', 'é', 'à', '`');
$ersetzen_array = array ('ae', 'oe', 'ue', 'ss', '', 'e', 'a','');
$name[] = str_replace($such_array, $ersetzen_array, $sWho);
# check if more words in var
if (count(explode(' ', $sWho)) > 1) {
# more pos for file names, e.g. tom.jpg or mueller.jpg
$aNamePic = explode(' ', $sWho) ;
$name[] = $aNamePic[0] ;
$name[] = $aNamePic[1] ;
}
// var_dump($name);
foreach ($name as $value ) {
// returns array with path and file
$check= glob($_SERVER['DOCUMENT_ROOT']. '/ImagesHighQuality/'.$value . ".*");
// var_dump($check);
// return $check[0]; not working..
# checks pic
if ($check ) {
# Array with a)extension, b)only filename, c)path without file (dirname) and d) file+ext(pathname)
$info = pathinfo($check[0]);
// var_dump($check);
// filename with ext.
$fileExt=$info['basename'];
return $fileExt;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment