All pastes #331414 Raw Edit

Stuff

public text v1 · immutable
#331414 ·published 2007-01-28 21:33 UTC
rendered paste body
<?php

/*
*/

function agenda_settings() {
  $form = array();
  $form['agenda_block_max_list_count'] = array(
     '#type'		=> 'textfield',
     '#title'		=> t('Maximum number of block agenda'),
     '#default_value'	=> variable_get('agenda_block_max_list_count', 3),
     '#description'	=> t('The maximum number of items listed in the agenda block'),
     '#required'	=> FALSE, 
     '#weight'		=> 0
  );
  return $form; 
}

function agenda_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t('Enables the creation of agenda pages ');
    case 'node/add#agenda':
      return t('Un évènement. Ajouter un évènement à la page.');
  }
}

function agenda_perm() {
     return array('Ajouter évènement', 'éditer évènement');
}

function agenda_access($op, $node) {
  global $user;
	
  if ($op == 'create') {
	  return user_access('create agenda');
  }
    else if ($op == 'view') {
 	 return user_access('access content');
  }
  else if ($op == 'update' ||  $op == 'delete') {
	if($user->uid == $node->uid || user_access('edit agenda')) {
	   		return true;
	}
	else {
		return false;
	}
  }
  else {
  	return false;
  }
}


function agenda_menu($may_cache) {
   $items = array();
      if ($may_cache) {
         $items[] = array('path'     => 'agenda/add',
                          'title'    => t('Add a new agenda'), 
                          'access'   => node_access('create', 'agenda'),
                          'type'     => MENU_CALLBACK,
                          'callback arguments' => array('agenda'),
                          'callback' => 'node_add');			 
						  
         $items[] = array('path'     => 'agenda',
                          'title'    => t('agenda'),
                          'access'   => user_access('access content'),
                          'type'     => MENU_CALLBACK,
                          'callback' => 'agenda_all');		
						  
		$items[] = array('path'     => 'agenda_datevenement',
                          'title'    => t('datevenement du depute'),
                          'access'   => user_access('access content'),
                          'type'     => MENU_CALLBACK,
                          'callback' => 'agenda_datevenement');		
						  
		$items[] = array('path'     => 'agenda_lieu',
                          'title'    => t('lieu du depute'),
                          'access'   => user_access('access content'),
                          'type'     => MENU_CALLBACK,
                          'callback' => 'agenda_lieu');			 
      }
      else {
         if(is_numeric(arg(1))) {			
            $node = node_load(arg(1));
            $items[] = array('path'     => 'agenda/' . arg(1),
                             'title'    => t('View an agenda'),
                             'access'   => node_access('view', $node),
                             'type'     => MENU_CALLBACK,
                             'callback' => 'node_page');                      
            $items[] = array('path'     => 'agenda/' . arg(1) . '/view',
                             'title'    => t('View an agenda'),
                             'access'   => node_access('view', $node),
                             'type'     => MENU_CALLBACK,
                             'callback' => 'node_page');                      
            $items[] = array('path'     => 'agenda/' . arg(1) . '/edit', 
                             'title'    => t('Edit an agenda'),
                             'access'   => node_access('edit', $node),
                             'type'     => MENU_CALLBACK,
                             'callback' => 'node_page');           
            $items[] = array('path'     => 'agenda/' . arg(1) . '/delete', 
                             'access'   => node_access('delete', $node),
                             'type'     => MENU_CALLBACK,
                             'callback' => 'node_delete_confirm');			
		}						 
	}
  	return $items;
}

function agenda_link($type, $node = NULL, $teaser = FALSE) {
   global $user;
   $links = array();
	
   if($type == 'node' && $node->type == 'agenda') {
      if (node_access('create', 'agenda')) {			
         $links[] = l(t('Add'), "node/add/agenda", 
                      array('title' => t('Add a new agenda'))); 
      }
      if (node_access('update', $node)) {
         $links[] = l(t('Edit'), "agenda/$node->nid/edit",
                      array('title' => t('Edit agenda ') . $node->title)); 

         $links[] = l(t('Delete'), "agenda/$node->nid/delete",
                      array('title' => t('Delete agenda ') . $node->title)); 
      }
   }
   return $links;
}


function agenda_form(&$node) {

   $form['title'] = array('#type' => 'textfield',
      '#title'         => t('title'),
      '#default_value' => $node->title,
      '#description'   => t('nom du évènement'),
      '#required'      => TRUE, 
      '#weight'        => 1
   );
   $form['datevenement'] = array('#type' => 'textfield',
      '#title'         => t('datevenement'),
      '#default_value' => $node->datevenement,
      '#description'   => t('datevenement du évènement'),
      '#required'      => TRUE, 
      '#weight'        => 2
   );
   $form['lieu'] = array('#type' => 'textfield',
      '#title'         => t('lieu'),
      '#default_value' => $node->lieu,
      '#description'   => t('lieu du évènement'),
      '#required'      => TRUE, 
      '#weight'        => 3
   );
   $form['body'] = array('#type' => 'textarea',
      '#title'         => t('body'),
      '#default_value' => $node->body,
      '#description'   => t('Contenu de la page du évènement!'),
      '#required'      => TRUE, 
      '#weight'        => 10 
   );
   return $form;
}
	
function agenda_load(&$node) {
   $additions = db_fetch_object(db_query('SELECT * FROM {agenda} ' .
                                         'WHERE nid = %d', $node->nid));
   return $additions;
}

function agenda_insert($node) {
 db_query("INSERT INTO {agenda} (nid, title, datevenement, lieu, body) ".
          "VALUES (%s, '%s', '%s', '%s', '%s')", 
          $node->nid, $node->title, $node->datevenement, $node->lieu, $node->body);
}

function agenda_update($node) {

$sql .= 'UPDATE agenda SET nid = ';
$sql .=  $node->nid;
$sql .= ', title = \'';
$sql .=  strtr($node->title, "'", "\'");
$sql .= '\', datevenement = \'';
$sql .=  $node->datevenement;
$sql .= '\', lieu = \'';
$sql .=  strtr($node->lieu, "'", "\'");
$sql .= '\', body = \'';
$sql .=  strtr($node->body, "'", "\'");
$sql .= '\' WHERE agenda.nid =';
$sql .=  $node->nid;
$sql .= ' LIMIT 1' ;

   db_query($sql);
}

function agenda_delete($node) {
   db_query('DELETE FROM {agenda} WHERE nid = %d', $node->nid);
}

function agenda_cron() {
   $queryResult = db_query("update {node} AS n INNER JOIN {agenda} AS a " .
       "ON n.nid = a.nid SET n.status = 0 WHERE n.type='agenda' ");
}

function agenda_nodeapi(&$node, $op) {
   switch ($op) {
      case 'update index':
         if ($node->type == 'agenda') {
            $text = ''; 
            $q = db_query('SELECT a.title, a.datevenement, a.lieu FROM node n LEFT JOIN agenda a ' .
                          'ON n.nid = a.nid WHERE n.nid = %d', $node->nid);
		if ($r = db_fetch_object($q)) {
		   $text = $r->title . ', ';
		   $text = $r->datevenement . ', ';
		   $text = $r->lieu . ',';
		   $text = $r->body;		   
		}
		return $text;
		}
	}
}

function agenda_node_info() {
 return array('agenda' => array('name' => 'agenda', 
                                      'base' => 'agenda'));
}


//page évènement
function agenda_all() {

$sql .= 'SELECT d.nid, d.title, d.datevenement, d.lieu, d.body, f.filepath ';
$sql .= 'FROM agenda d, files f, image_attach ia ';
$sql .= 'WHERE d.nid = ia.nid ';
$sql .= '&& ia.iid = f.nid ';
$sql .= 'GROUP BY nid ';
$sql .= 'ORDER BY d.title ASC ';
  
$tags = "";
$limit = 3; //éléments par pages
$element = 0;		

$result = pager_query($sql, $limit, $element, 'SELECT COUNT(nid) FROM {agenda}');

	while ($items = db_fetch_object($result)) {
		$rows[] = array(
                    $items->nid,
                    $items->title,
                    $items->datevenement,
                    $items->lieu,
					$items->body,
					$items->filepath
                    );
	}
  
  drupal_set_title(check_plain($node->title)); 	

    $output .= '<div class="coloneDroiteInt">';	
	$output .= '<div class="deputeBarSous">';
	$output .= '<div class="floatLeft">';	
	$output .= html_entity_decode(theme( 'pager_previous',($tags[3] ? $tags[3] : '<img src="themes/pq/images/bt_pagePrec_gris.gif" />'), $limit, $element, 1, NULL));	
	$output .= '</div>';
	$output .= '<div class="floatRight">';
	$output .= html_entity_decode(theme( 'pager_next',($tags[3] ? $tags[3] : '<img src="themes/pq/images/bt_pageSuiv_gris.gif" />'), $limit, $element, 1, NULL));
	$output .= '</div>';
	$output .= '</div>';
		
	for($j = 0; $j < count($rows); $j++) {
	
		$output .= '  <div class="nouvellesDiv">';		
		$output .=  '<a href="?q=agenda/';
		$output .=  $rows[$j][0];
		$output .=  '">';		
		$output .=  '<img src="files/'.$rows[$j][5].'" alt="" width="50" height="65" border="0" class="deputeThumbs" />';		
		$output .= '<span class="titreNouvelle">';
		$output .= $rows[$j][1];
		$output .= '</span><br />';		
		$output .=  '</a>';		
		$output .= '<span class="date">';
		$output .= $rows[$j][2];
		$output .= '</span><br />';		
		$output .= $rows[$j][4];		
		$output .= '<br /></div>';
	
	}	
	$output .= '<div class="deputeBarSous">';	
	$output .= '<div class="floatLeft">';
	$output .= html_entity_decode(theme( 'pager_previous',($tags[3] ? $tags[3] : '<img src="themes/pq/images/bt_pagePrec_gris.gif" />'), $limit, $element, 1, NULL));
	$output .= '</div>	';	
	$output .= '<div class="floatRight">';
	$output .= html_entity_decode(theme( 'pager_next',($tags[3] ? $tags[3] : '<img src="themes/pq/images/bt_pageSuiv_gris.gif" />'), $limit, $element, 1, NULL));
	$output .= '</div>';		
	$output .= '</div>	';
	
  return $output;
}

//page évènement
function agenda_datevenement() {
  return $output;
}

//page évènement
function agenda_lieu() {
  return $output;
}
	
	
?>