/[drupal]/contributions/modules/tngintegrate/tngintegrate.module
ViewVC logotype

Contents of /contributions/modules/tngintegrate/tngintegrate.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Thu Feb 22 05:53:41 2007 UTC (2 years, 9 months ago) by arturoramos
Branch: MAIN
CVS Tags: DRUPAL-4-6--1-0, DRUPAL-5--1-0, HEAD
Branch point for: DRUPAL-6--1
Changes since 1.2: +6 -8 lines
File MIME type: text/x-php
Fixing bugs related to tng_users database structure and reverting drupal_mail() function to php mail() function since Drupal 4.6 has no drupal_mail() function.
1 <?php
2
3 /**
4 * @file
5 * Integrates Darrin Lythgoe's The Next Generation genealogy software with Drupal user database.
6 */
7
8 /**
9 * Implementation of hook_menu().
10 */
11 function tngintegrate_menu($may_cache) {
12 $items = array();
13 if ($may_cache) {
14 $items[] = array(
15 // 'path' => 'tng', 'title' => t('TNG Genealogy'),
16 'path' => 'gedcom', 'title' => t('TNG GEDCOM Database'),
17 'access' => user_access('access TNG'),
18 'callback' => 'tngintegrate_login',
19 'type' => MENU_SUGGESTED_ITEM);
20
21 $items[] = array(
22 'path' => 'admin/settings/tng',
23 'title' => t('TNG Genealogy'),
24 'description' => t('Configure integration with The Next Generation Genealogy software.'),
25 'callback' => 'tngintegrate_settings',
26 'access' => user_access('administer site configuration'),
27 );
28
29 }
30 return $items;
31 }
32
33 function tngintegrate_perm() {
34 return array('access TNG');
35 }
36
37
38 /**
39 * Implementation of hook_settings for 4.6
40 * Deprecated in 5.0 here for legacy only
41 **/
42 function tngintegrate_settings() {
43 $output = '';
44 $output.= form_textfield(
45 t('Location of TNG'),
46 'tng_dir',
47 variable_get('tng_dir', 'tng/'),
48 64, 64,
49 t('Path to your TNG directory. Please include a trailing slash ("/").')
50 );
51 $output.= form_textfield(
52 t('Name of TNG user table'),
53 'tng_table',
54 variable_get('tng_table', 'tng_users'),
55 64, 64,
56 NULL
57 );
58 $output .= form_checkboxes(
59 t('Error logging'), 'tng_error_mode',
60 variable_get('tng_error_mode', array(1)),
61 array(1 => t('Watchdog'),
62 2 => t('Output to the browser')),
63 t('Choose where errors are displayed')
64 );
65 $output.= form_textfield(
66 t('TNG administrator email address'),
67 'tng_adminaddress',
68 variable_get('tng_adminaddress', variable_get('site_mail', ini_get('sendmail_from'))),
69 64, 64,
70 NULL
71 );
72 $output.= form_textfield(
73 t('Subject line for TNG welcome e-mail message'),
74 'tng_welcomesubject',
75 variable_get('tng_welcomesubject', 'Welcome to TNG'),
76 64, 64,
77 NULL
78 );
79 $output.= form_textarea(
80 t('Text of TNG welcome e-mail message'),
81 'tng_welcomemessage',
82 variable_get('tng_welcomemessage', 'You have been granted access to TNG Genealogy software.'),
83 100, 5,
84 NULL
85 );
86 return $output;
87 }
88
89
90 function tngintegrate_login() {
91 global $user;
92 global $tngurl;
93 global $admin_email;
94 $users_table = variable_get(tng_table, NULL);
95 $f_username = $user->name;
96 $uid = $user->uid;
97 $basedir = variable_get(tng_dir, NULL);
98
99 // Generate new random password for TNG table
100 $pwd = _tngintegrate_ranpass();
101 $pwd_encrypt = base64_encode( $pwd );
102 // For TNG Version 6.0 and above the above line needs to be replaced by the line below.
103 // $pwd_encrypt = md5( $pwd );
104 $query = "SELECT * FROM {$users_table} WHERE username = '%s' ";
105 $resulttng = db_query($query, $f_username);
106 $found = mysql_num_rows( $resulttng );
107 if ( $found == 0 ) {
108 if ($f_username !=""){
109 $adding = "INSERT INTO {$users_table} (description, username, password, realname, email, lastlogin) VALUES ('%s','%s','%s','%s', '%s', NOW()) ";
110 $added = db_query($adding, $f_username, $f_username, $pwd_encrypt, $f_username, $user->mail);
111 if ($added) {
112 watchdog('tngintegrate', t('New user %name created in TNG user table %table.', array('%name' => $f_username, '%table' => $users_table)));
113 }
114 else {
115 watchdog('tngintegrate', t('Error creating new user in TNG user table %table.'.mysql_error(), array('%name' => $f_username, '%table' => $users_table)), WATCHDOG_ERROR);
116 }
117 $header = "From: ".$from = variable_get(tng_adminaddress, NULL)."\n";
118 $subject = variable_get(tng_welcomesubject, NULL);
119 $body = variable_get(tng_welcomemessage, NULL);
120 $mail_success = mail($user->mail, $subject, $body, $header);
121 if ($mail_success) {
122 watchdog('tngintegrate', t('New user created in TNG user table and notification email sent (%name at %email).', array('%name' => $f_username, '%email' => $user->mail)));
123 }
124 else {
125 watchdog('user', t('Error mailing notification of new TNG user creation (%name at %email).', array('%name' => $account->name, '%email' => $account->mail)), WATCHDOG_ERROR);
126 }
127
128 $query = "SELECT password FROM {$users_table} WHERE username = '%s'";
129 $resulttng = db_query($query, $f_username) ;
130 $found = mysql_num_rows( $resulttng );
131 }
132 } else {
133 $query = "UPDATE {$users_table} SET password = '%s' WHERE username = '%s'";
134 db_query($query, $pwd_encrypt, $f_username);
135 }
136 $row = mysql_fetch_row( $resulttng );
137 ob_start();
138 $output = "<SCRIPT>";
139 $output .= 'var frameSrc = "";';
140 $output .= 'frameSrc += "<HTML><BODY>";';
141 $output .= 'frameSrc += "<FORM name=login method=post action='. variable_get (tng_dir,'/tng/').'processlogin.php>";';
142 $output .= 'frameSrc += "<input type=hidden name=tngusername value=\"'.$f_username.'\">";';
143 $output .= 'frameSrc += "<input type=hidden name=tngpassword value='.$pwd.'>";';
144 $output .= 'frameSrc += "</FORM>";';
145 $output .= 'frameSrc += "<script>";';
146 $output .= 'frameSrc += "document.login.submit();";';
147 $output .= 'frameSrc += "<\/script>";';
148 $output .= 'frameSrc += "<\/BODY><\/HTML>";';
149 $output .= 'var iframeWin;';
150 $output .= 'function init(){';
151 $output .= ' iframeWin = window.frames.anIframe;';
152 $output .= ' iframeWin.document.open();';
153 $output .= ' iframeWin.document.write(frameSrc);';
154 $output .= ' iframeWin.document.close();';
155 $output .= '}';
156 $output .= '</SCRIPT>';
157 $output .= '<IFRAME ID="anIframe" NAME="anIframe" SRC="about:blank" WIDTH="100%" HEIGHT="800px"';
158 $output .= 'hspace=0 vspace=0 marginwidth=0 marginheight=0 frameborder=0 scrolling=auto>';
159 $output .= '</IFRAME>';
160 $output .= '<script>';
161 $output .= ' init();';
162 $output .= '</script>';
163 ob_end_clean();
164 print theme('page', $output);
165 }
166
167
168 function tngintegrate_error($message, $ret) {
169 $error_mode = variable_get('tng_error_mode', array());
170 if (in_array(2, $error_mode)) {
171 drupal_set_message($message);
172 }
173
174 if (isset($ret)) {
175 $full_message = $message . '<br/>' . $ret->getAsHtml();
176 } else {
177 $full_message = $message;
178 }
179
180 if (in_array(1, $error_mode)) {
181 watchdog('tng', $full_message, WATCHDOG_ERROR);
182 }
183 }
184
185 function _tngintegrate_ranpass($len = "8"){
186 $pass = NULL;
187 for($i=0; $i<$len; $i++) {
188 $char = chr(rand(48,122));
189 while (!ereg("[a-zA-Z0-9]", $char)){
190 if($char == $lchar) continue;
191 $char = chr(rand(48,90));
192 }
193 $pass .= $char;
194 $lchar = $char;
195 }
196 return $pass;
197 }
198
199 ?>

  ViewVC Help
Powered by ViewVC 1.1.2