? invvoucher.pages.inc
? port_6.patch
Index: invvoucher.admin.inc
===================================================================
RCS file: invvoucher.admin.inc
diff -N invvoucher.admin.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ invvoucher.admin.inc	23 Oct 2008 18:54:33 -0000
@@ -0,0 +1,45 @@
+<?php
+
+/**
+ *   Admin settings
+ */
+function invvoucher_admin_settings() {
+	global $base_url;
+	
+	$form['email_settings'] = array(
+	'#type' => 'fieldset',
+	'#title' => t('Email settings'),
+	'#collapsible' => TRUE,
+	'#collapsed' => FALSE,
+	);
+	
+	$form['email_settings']['invvoucher_subject'] = array(
+	'#type' => 'textfield',
+	'#title' => t('Subject'),
+	'#default_value' => variable_get('invvoucher_subject', t("You've been invited")),
+	'#size' => 40,
+	'#maxlength' => 64,
+	'#description' => t('Type the subject of the invitation email.'),
+	'#required' => TRUE,
+	);
+	
+	$form['email_settings']['invvoucher_default_mail_template'] = array(
+	'#type' => 'textarea',
+	'#title' => t('Mail template'),
+	'#default_value' => invvoucher_get_mail_template(),
+	'#required' => TRUE,
+	'#rows' =>10,
+	'#description' => t('Use the following placeholders: @site, @homepage, @join_link, @message, @inviter, @code, @expired.'),
+	);
+	
+	$form['invvoucher_register_URL'] = array(
+	'#type' => 'textfield',
+	'#title' => t('Registration page URL'),
+	'#default_value' => variable_get('invvoucher_register_URL', $base_url),
+	'#required' => FALSE,
+	'#description' => t('Place here your \'Create account page\' URL'),
+	);
+	return system_settings_form($form);
+}
+
+
Index: invvoucher.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/invvoucher/invvoucher.info,v
retrieving revision 1.2
diff -u -p -r1.2 invvoucher.info
--- invvoucher.info	17 Sep 2008 21:38:59 -0000	1.2
+++ invvoucher.info	23 Oct 2008 18:54:33 -0000
@@ -1,7 +1,8 @@
 ; $Id: invvoucher.info,v 1.2 2008/09/17 21:38:59 dearanton Exp $
 name = Invitation Voucher
 description = "Administrator can send invitation voucher to friends for registration at his site "
-pakage = Other
+package = Other
+core = 6.x
 
 version = "$Name:  $"
-project = "invvoucher"
\ No newline at end of file
+project = "invvoucher"
Index: invvoucher.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/invvoucher/invvoucher.install,v
retrieving revision 1.2
diff -u -p -r1.2 invvoucher.install
--- invvoucher.install	17 Sep 2008 21:39:00 -0000	1.2
+++ invvoucher.install	23 Oct 2008 18:54:33 -0000
@@ -2,57 +2,11 @@
 //$Id: invvoucher.install,v 1.2 2008/09/17 21:39:00 dearanton Exp $
 // invitation voucher drupal module install
 
+/**
+ * Implementation of hook_install()
+ */
 function invvoucher_install() {
-drupal_set_message("Yo");
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      $result1 = db_query("
-    	CREATE TABLE `invvoucher` (
-		`code` VARCHAR( 10 ) NOT NULL ,
-		`reg_count` INT DEFAULT '0' NOT NULL ,
-		`date_sent` INT DEFAULT '0' NOT NULL ,
-		`date_exp` INT DEFAULT '0' NOT NULL ,
-      	`email` VARCHAR( 30 ) NOT NULL,
-		PRIMARY KEY ( `code` ) ,
-		INDEX ( `date_sent` ) 
-	);"
-      );
-      $result2 = db_query("ALTER TABLE {invvoucher} ADD INDEX (date_exp)");
-      $result3 = db_query("
-    	CREATE TABLE `invvoucher_users` (
-		`code` VARCHAR( 10 ) NOT NULL ,
-		`uid` VARCHAR( 10 ) NOT NULL ,
-		PRIMARY KEY ( `uid` ) ,
-		INDEX ( `code` ) 
-	);"
-      );
-      break;
-
-    case 'pgsql':
-      $result1 = db_query("
-        CREATE TABLE {invvoucher} (
-          code VARCHAR(10) NOT NULL,
-          reg_count INT NOT NULL DEFAULT '0',
-          date_sent INT NOT NULL DEFAULT '0',
-          date_exp  INT NOT NULL DEFAULT '0',
-      	  email		VARCHAR( 30 ) NOT NULL,
-          PRIMARY KEY (code),
-	  INDEX ( date_sent , date_exp ) 
-        );"
-      );
-      $result2 = db_query("CREATE INDEX {invvoucher}_date_exp_idx ON {invvoucher} (date_exp)");
-      $result1 = db_query("
-        CREATE TABLE {invvoucher_users} (
-          code VARCHAR(10) NOT NULL,
-          uid VARCHAR(10) NOT NULL,
-          PRIMARY KEY (code),
-	  INDEX ( uid , code ) 
-        );"
-      );
-
-      break;
-  }
+  drupal_install_schema('invvoucher');
 
   if ($result1 && $result2 && $result3) {
     drupal_set_message(t('The database schema for the Invitation Voucher module has been successfully updated.'));
@@ -62,7 +16,68 @@ drupal_set_message("Yo");
   }
 }
 
+/**
+ * Implementation of hook_uninstall()
+ */
 function invvoucher_uninstall() {
 	db_query('DROP TABLE {invvoucher}');
 	db_query('DROP TABLE {invvoucher_users}');
 }
+
+/**
+ * Implementation of hook_schema().
+ */
+function invvoucher_schema() {
+  $schema['invvoucher'] = array(
+    'description' => t('foo'),
+    'fields' => array(
+      'code' => array(
+        'type' => 'varchar',
+        'length' => 10,
+        'not null' => TRUE,
+      ),
+      'reg_count' => array(
+        'type' => 'int',
+        'default' => 0,
+        'not null' => TRUE,
+      ),
+      'date_sent' => array(
+        'type' => 'int',
+        'default' => 0,
+        'not null' => TRUE,
+      ),
+      'date_exp' => array(
+        'type' => 'int',
+        'default' => 0,
+        'not null' => TRUE,
+      ),
+      'email' => array(
+        'type' => 'varchar',
+        'length' => 30,
+        'not null' => TRUE,
+      ),
+    ),
+    'primary key' => array('code'),
+    'index' => array('date_sent'),
+  );
+
+  $schema['invvoucher_users'] = array(
+    'description' => t('bar'),
+    'fields' => array(
+      'code' => array(
+        'type' => 'int',
+        'default' => 0,
+        'not null' => TRUE,
+      ),
+      'uid' => array(
+        'type' => 'int',
+        'default' => 0,
+        'not null' => TRUE,
+      ),
+      'primary key' => array('uid'),
+      'index' => array('code'),
+    ),
+  );
+
+  return $schema;
+}
Index: invvoucher.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/invvoucher/invvoucher.module,v
retrieving revision 1.2
diff -u -p -r1.2 invvoucher.module
--- invvoucher.module	17 Sep 2008 21:39:00 -0000	1.2
+++ invvoucher.module	23 Oct 2008 18:54:36 -0000
@@ -28,204 +28,37 @@ function invvoucher_perm() {
 
 /**
  *   Menu items
+ * Implementation of hook_menu().
  */
-function invvoucher_menu($may_cache) {
-	$items = array();
-	if ($may_cache) {
-		$items[] = array(
-		'path' => 'admin/user/invvoucher',
-		'title' => t('Invitation voucher'),
-		'description' => t('Administer how and where Invitation Voucher are used.'),
-		'callback' => 'drupal_get_form',
-		'callback arguments' => array('invvoucher_admin_settings'),
-		'access' => user_access('administer site configuration'),
-		'type' => MENU_NORMAL_ITEM
-		);
-		
-		$items[] = array(
-		'path' => 'invvoucher',
-		'title' => t('Send invitation voucher'),
-		'callback' => 'drupal_get_form',
-		'callback arguments' => array('invvoucher_send_form'),
-		'access' => user_access('send invitation voucher'),
-		'type' => MENU_NORMAL_ITEM
-		);
-		
-		$items[] = array(
-		'path' => 'invvoucher/delete',
-		'callback' => 'invvoucher_delete',
-		'access' => user_access('administer site configuration'),
-		'type' => MENU_CALLBACK,
-		);
-	}
-	return $items;
-}
-
-/**
- *   Admin settings
- */
-function invvoucher_admin_settings() {
-	global $base_url;
-	
-	$form['email_settings'] = array(
-	'#type' => 'fieldset',
-	'#title' => t('Email settings'),
-	'#collapsible' => TRUE,
-	'#collapsed' => FALSE,
-	);
-	
-	$form['email_settings']['invvoucher_subject'] = array(
-	'#type' => 'textfield',
-	'#title' => t('Subject'),
-	'#default_value' => variable_get('invvoucher_subject', t("You've been invited")),
-	'#size' => 40,
-	'#maxlength' => 64,
-	'#description' => t('Type the subject of the invitation email.'),
-	'#required' => TRUE,
-	);
-	
-	$form['email_settings']['invvoucher_default_mail_template'] = array(
-	'#type' => 'textarea',
-	'#title' => t('Mail template'),
-	'#default_value' => invvoucher_get_mail_template(),
-	'#required' => TRUE,
-	'#rows' =>10,
-	'#description' => t('Use the following placeholders: @site, @homepage, @join_link, @message, @inviter, @code, @expired.'),
-	);
-	
-	$form['invvoucher_register_URL'] = array(
-	'#type' => 'textfield',
-	'#title' => t('Registration page URL'),
-	'#default_value' => variable_get('invvoucher_register_URL', $base_url),
-	'#required' => FALSE,
-	'#description' => t('Place here your \'Create account page\' URL'),
-	);
-	return system_settings_form($form);
-}
-
-/**
- *   Send invitation voucher form
- */
-function invvoucher_send_form() {
-	
-	$form['invvoucher_settings'] = array(
-	'#type' => 'fieldset',
-	'#title' => t('Invitation Voucher settings'),
-	'#collapsible' => TRUE,
-	'#collapsed' => FALSE,
-	);
-	
-	$form['invvoucher_settings']['invvoucher_expiration_date'] = array(
-	'#type' => 'textfield',
-	'#title' => t('date of expiration'),
-	'#default_value' => variable_get('invvoucher_expiration_date',date("Y-m-d")),
-	'#required' => TRUE,
-	'#description' => t('Date, when your voucher will expire (YYYY-MM-DD)'),
-	);
-	
-	$form['invvoucher_settings']['invvoucher_quantity'] = array(
-	'#type' => 'select',
-	'#title' => t('Voucher quantity'),
-	'#default_value' => variable_get('invvoucher_quantity', 1),
-	'#options' => array(1 => 1, 2 => 2, 3 => 3, 5 => 5, 10 => 10, 20 => 20, -1 => t('Unlimited')),
-	'#description' => t('How much users can use this voucher'),
-	'#multiple' => FALSE,
-	'#required' => TRUE,
-	);
-	
-	$form['invvoucher_recipient'] = array(
-	'#type' => 'textfield',
-	'#title' => t('Email of invited person'),
-	'#default_value' => variable_get('invvoucher_recipient',''),
-	'#required' => TRUE,
-	'#description' => t('Email'),
-	);
-	
-	$form['invvoucher_code'] = array(
-	'#type' => 'submit',
-	'#value' => t('Send voucher'),
-	);
-	
-	// Show list of sent invitations
-	$form['invvoucher_sent'] = array(
-	'#type' => 'fieldset',
-	'#title' => t('Sent invitation vouchers'),
-	'#collapsible' => TRUE,
-	'#collapsed' => TRUE,
+function invvoucher_menu() {
+	$items['admin/user/invvoucher'] = array(
+    'title' => 'Invitation voucher',
+    'description' => 'Administer how and where Invitation Voucher are used.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('invvoucher_admin_settings'),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_NORMAL_ITEM,
+    'file' => 'invvoucher.admin.inc',
+	);
+	
+	$items['invvoucher'] = array(
+    'title' => 'Send invitation voucher',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('invvoucher_send_form'),
+    'access arguments' => array('send invitation voucher'),
+    'type' => MENU_NORMAL_ITEM,
+    'file' => 'invvoucher.pages.inc',
+	);
+	
+	$items['invvoucher/delete'] = array(
+    'page callback' => 'invvoucher_delete',
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_CALLBACK,
+    'file' => 'invvoucher.pages.inc',
 	);
 
-	if ( user_access('administer site configuration') ) {
-		$result = db_query('SELECT uid, name FROM `users` WHERE 1');
-		$users = array();
-		while ( $row = mysql_fetch_array($result) ) 
-			$users[ $row['uid'] ] = $row['name'];
-
-		global $user;
-
-		$form['invvoucher_sent']['filter'] = array(
-		'#type' => 'select',
-		'#title' => t('Filter'),
-		'#default_value' => $user->uid,
-		'#options' => $users,
-		'#description' => t('Choose voucher owners to view'),
-		'#multiple' => FALSE,
-		'#required' => FALSE,
-	);
-	}
-	
-	/**
-	 *Display list of sent and registerd with them users
-	 */
-	// select all availble invitation vouchers
-	$query = db_query("SELECT * FROM invvoucher ORDER BY date_exp DESC");
-	//if (!empty($query)) {
-		while ($row = mysql_fetch_array($query)) {
-			$name = '';
-			$email = '';
-			$created = '';
-			if (user_access('administer site configuration'))
-				$delete_link=l(t('delete'), 'invvoucher/delete/'.urlencode($row['code']));
-			else
-				$delete_link='';
-			//	look for users registered with each voucher
-			$subquery =  db_query("SELECT t1.*, t2.mail, t2.created FROM users AS t2, invvoucher_users AS t1 WHERE t1.code = '%s' AND t2.name = t1.uid", $row['code']);
-			while ( $sub_row = mysql_fetch_array($subquery) ) {
-				$name.=$sub_row['uid'].'<BR>';
-				$email.=$sub_row['mail'].'<BR>';
-				$created.=date("Y-m-d",$sub_row['created']).'<BR>';
-			}
-			if ( empty( $name ) ) {
-					$name = t('No registration yet');
-					$email = '-';
-					$created = '-';
-			}
-			$expired = date("Y-m-d", $row['date_exp']);
-			//	color expired date with red
-			if ( $row['date_exp'] < time() )
-				$expired = "<div style='color : red'>".$expired."</div>";
-				
-			$items[] = array($row['code'], $name, $email, $created,($row['reg_count']!=-1)?$row['reg_count']:t('Unlimited'), $expired, $delete_link);
-		}
-		//	format results as table
-		if ( count($items)>0 ) {
-			$header = array(t('Voucher'), t('Nickname(s)'),t('Email(s)'), t('Registered'), t('Quantity'), t('Voucher expires'),'');
-			$table = theme('table', $header, $items, array('id' => 'invvoucher_sent_table'));
-		}
-	//}
-	else {
-		$header = array (' ');
-		$items[] = array ( t("No invitation vouchers was sent") );
-		$table = theme('table', $header, $items, array('id' => 'invvoucher_sent_table'));
-	}
-	
-	$form['invvoucher_sent']['invvoucher_sent_table'/*invvouchers'*/] = array(
-	'#type' => 'markup',
-	'#value' => $table,
-	);
-	
-	return $form;
+	return $items;
 }
-
 /**
  *   Send email with code
  */
@@ -258,38 +91,6 @@ function invvoucher_send_invite($op, $us
   }
 }
 
-/**
- *   Send form submit handler
- */
-function invvoucher_send_form_submit($form_id, $edit) {
-
-  	global $user;
-  	$errors =0;
-  	$email = $edit['invvoucher_recipient'];
-  	if (!valid_email_address($email)) {
-		drupal_set_message( t('Incorrect email'),'error');
-		$errors++;
-  	}
-	$code = invvoucher_create();
-    $message = trim($edit['message']);
-    $quantity = $edit['invvoucher_quantity'];
-    
-    if (!$expired = datestr2unixtime($edit['invvoucher_expiration_date'])) {
-    	$errors++;
-    }
-    else
-    	// invitation expires at 23.59, not at 00.00 of the same day!
-    	$expired += 60*60*23+60*59;
-    if (!$errors)
-    	if (invvoucher_send_invite('mail', $user->name, $email, $code, $message, $expired, $quantity)) {
-			db_query("INSERT INTO {invvoucher} (code, reg_count, date_sent, date_exp, email) VALUES ('%s', '%d', '%d', '%d', '%s')", 
-			$code, $quantity, time(), $expired, $email);
-        	// notify other modules
-        	$args = array('inviter' => $user);
-        	module_invoke_all('invvoucher', 'invvoucher', $args);
-        	drupal_set_message(t('Invitation voucher was sent to ').$email);
-      	}
-}
 
 /**
  *   Default mail template
@@ -346,7 +147,7 @@ function invvoucher_validate ($code) {
 /**
  *	Override registration form
  */
-function invvoucher_form_alter($form_id, &$form) {
+function invvoucher_form_alter(&$form, $form_state, $form_id) {
   if ($form_id == 'user_register')  {
   $form['#submit'] = array('invvoucher_submit' => array()) + $form['#submit'];
       if (module_hook('invvoucher', 'invvoucherchallenge')) {
@@ -454,4 +255,4 @@ function invvoucher_delete($code) {
 	else
 		watchdog('invvoucher', t('Detected malicious attempt to delete an invitation voucher.'), WATCHDOG_WARNING, l(t('view'), 'user/'. $user->uid));
 	drupal_goto('invvoucher');
-}
\ No newline at end of file
+}
