Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: Create a Listing of Contacts inside an Article  (Read 4786 times)

jlhaslip

  • Sr. Member
  • ****
  • Karma: 16
  • Posts: 374
    • My snews with AEF Forum site
Create a Listing of Contacts inside an Article
« on: September 23, 2008, 12:16:06 AM »

By combining the Contact List Mod by Philmoz, and the Insert Function into Articles Mod by Philmoz, this Mod will create a listing inside an Article based on the data stored in the Contacts Table of the database.
Steps:
Or here: (same one)
Code: [Select]
//CONTACT LIST/SUBJECT
//
// modified by jlhaslip on Sept 22, 2008 for the case(7)
// to be used with the Insert Function Mod by philmoz
// to be able to display the Contact List inside an Article.
// for example: an Association Executive List, or a Company's eMail List
// eMail addresses are linked to the sNews Contact page.
//
function contact_list($edit=0){
$select_show='position';// options are 'name' or 'position'
/* No real need to edit below, except for styling/formatting issues */
$link='<a href="'.db('website');
$con_select='';
/** SQL groups **/
$sql_all = "SELECT * FROM ".db('prefix')."contacts ORDER BY roworder ASC ";
$sql_0 = "SELECT id,$select_show,roworder FROM ".db('prefix')."contacts ORDER BY roworder ASC ";
$sql_6 = "SELECT id,name FROM ".db('prefix')."contacts";
$sql_1 = "SELECT id FROM ".db('prefix')."contacts";
/** count if 1 or more entry **/
$con_query = mysql_query($sql_1);
$con_result = mysql_num_rows($con_query);

if (is_numeric($edit)==TRUE) {
switch ($edit){
case 0 :// contacts pick list
if ($con_result<1){
$con_select .= html_input('hidden', 'contact_person', 'contact_person', '0', '', '', '', '', '', '', '', '', '', '', '');}else{
$cont_query = $sql_0;
$cont_result = mysql_query($cont_query);
$con_select .= '<p><label for="contact_person">'.l('contact_person').'</label>:<br />';
$con_select .= '<select name="contact_person" id="cp">';
$con_select .= '<option value="0">'.l('general_contact').'</option>';
while ($r = mysql_fetch_array($cont_result)) {
$alt = $alt == 0?1:0;$clss = $alt == 1?' class="contact_list_op_alt" ':' class="contact_list_op_norm"';
$con_select.= '<option value="'.$r['id'].'"'.$clss.' >'.$r[$select_show].'</option>';
}
$con_select.='</select></p>';}
$con_select .= html_input('text', 'subject', 'subject', '', l('subject'), 'text', '', '', '', '', '', '', '', '', '');
break;
case 1: // edit/new/view links. Call display (case 2)
$cont_query = $sql_1;
$cont_result = mysql_query($cont_query);
$cont_rows=mysql_num_rows($cont_result);
$showlinks= $cont_rows>=1?true:false;
$con_select .= html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', '<a title="'.l('a_contact_group').'" onclick="toggle(\'sub2a\')" style="cursor: pointer;">'.l('a_contact_group').'</a>');
$con_select .= '<div id="sub2a" style="display:none;"><p>';
$con_select .= l('contact_list').' &middot; ';
$con_select .= $link.'add_contact/">'.l('add_new').'</a>';
if ($showlinks===true){
$con_select .= ' &middot; '.$link.'admin_contact/">'.l('edit').'</a>';
$con_select .= ' &middot; <a title="'.l('view').'" onclick="toggle(\'sub2b\')" style="cursor: pointer;">'.l('view').'</a>';
$con_select .= '</p><div id="sub2b" style="display:none;">';
$con_select .= contact_list(2);
$con_select .='</div>';
}
$con_select .='</div>';
$con_select .= '</fieldset>';
break;
case 2:// contact display in admin
$cont_query = $sql_all;
$cont_result = mysql_query($cont_query) or die();
$con_select .= '<table id="contact_listing" ><COLGROUP align="left"><COLGROUP align="left"><COLGROUP align="left"><COLGROUP align="center"><tr><th>'.l('contact_select_name').'</th><th>'.l('contact_select_position').'</th><th>'.l('contact_select_email').'</th><th>'.l('contact_select_roworder').'</th></tr>';
while ($r = mysql_fetch_array($cont_result)) {
$alt = $alt == 0?1:0;$clss = $alt == 0?' class="contact_list_alt" ':'';
$con_select .= '<tr><td'.$clss.' >'.$r['name'].'</td><td'.$clss.'>'.$r['position'].'</td><td'.$clss.'>'.$r['email'].'</td><td'.$clss.'>'.$r['roworder'].'</td></tr>';
}
$con_select.='</table>';
break;
case 3://contact edit
$cont_query = $sql_all;
$cont_result = mysql_query($cont_query);
$con_select .= html_input('form', 'post', '', '', '', '', '', '', '', '', '', '', 'post', 'index.php?action=process&amp;task=edit_contact', '');
$con_select .= html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', l('a_contact_group'));
$con_select .= '<table id="contact_listing"><COLGROUP align="left"><COLGROUP align="left"><COLGROUP align="left"><COLGROUP align="left"><COLGROUP align="center"><tr><th>&nbsp;</th><th>'.l('contact_select_name').'</th><th>'.l('contact_select_position').'</th><th>'.l('contact_select_email').'</th><th>'.l('contact_select_roworder').'</th></tr>';
while ($r = mysql_fetch_array($cont_result)) {
$alt = $alt == 0?1:0;$clss = $alt == 0?' class="contact_list_alt" ':'';
$con_select .= '<tr>';
$con_select .= '<td'.$clss.'><input type="radio" name="contact_edit[id]" value="'.$r['id'].'" id="coned" /></td>';
$con_select .= '<td'.$clss.'><input type="text" name="contact_edit['.$r['id'].'][name]" id="contact_name" value="'.$r['name'].'" /></td>';
$con_select .= '<td'.$clss.'><input type="text" name="contact_edit['.$r['id'].'][position]" id="contact_position" value="'.$r['position'].'" /></td>';
$con_select .= '<td'.$clss.'><input type="text" name="contact_edit['.$r['id'].'][email]" id="contact_email" value="'.$r['email'].'" /></td>';
$con_select .= '<td'.$clss.'><input size="2" type="text" name="contact_edit['.$r['id'].'][roworder]" id="contact_order" value="'.$r['roworder'].'" /></td>';
}$con_select.='</tr></table>';
$con_select.= html_input('hidden', 'task', 'task', 'edit_contact', '', '', '', '', '', '', '', '', '', '', '');
$con_select.= html_input('submit', 'update_contact', 'update_contact', l('update'), '', 'button', '', '', '', '', '', '', '', '', '');
$con_select.='&nbsp;&nbsp;';
$con_select.= html_input('submit', 'delete_contact', 'delete_contact', l('delete_selected'), '', 'button', 'onclick="javascript: return pop()"', '', '', '', '', '', '', '', '');
$con_select.= '</fieldset></form>';
break;
case 4://contact new form and processing
$cont_query = $sql_6;
$cont_result = mysql_query($cont_query);
$c = mysql_fetch_array($cont_result);
$cont_success = count($c['id'])>0?'yes':'no';
if (isset($_POST['add_contact'])){
$name = clean(cleanXSS($_POST['name']));
$position = clean(cleanXSS($_POST['position']));
$email = clean(cleanXSS($_POST['email']));
$roworder = is_integer($_POST['roworder'])?$_POST['roworder']:0;
$notempty = !empty($name)&&!empty($position)&&!empty($email)?'ok':'not';
if ($cont_success=='yes'){
$cont_query = $sql_all;
$cont_result = mysql_query($cont_query);
while ($r = mysql_fetch_array($cont_result)) {
if ($name==$r['name']&&$position==$r['position']&&$email==$r['email']){$repeat = 'not';break(1);}else{$repeat = 'ok';}
}}else{$repeat = 'ok';}
switch (true){
case $repeat == 'ok' && $notempty=='ok':$required = 'ok';break;
case $repeat != 'ok' && $notempty=='ok':$notify = l('repeated_entry');$required = 'not';break;
case $repeat == 'ok' && $notempty!='ok':$notify = l('incomplete');$required = 'not';break;
}
}
if ($required == 'ok'){
mysql_query("INSERT INTO ".db('prefix')."contacts(id, name, position, email, roworder) VALUES('NULL', '$name', '$position', '$email', '$roworder')");
$con_select .='</p>'.l('entered_lead').'&nbsp;'.$name.' / '.$position.'&nbsp;'.l('entered_tail').'</p>';
$con_select.= contact_list(2);
}else{
$con_select .= html_input('form', 'post', '', '', '', '', '', '', '', '', '', '', 'post', 'index.php?action=process&amp;task=add_contact', '');
$con_select .= html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', l('a_contact_group'));
$con_select .= '<p>'.l('required').'</p>';
$con_select .= $notify;
$con_select .= html_input('text', 'name', 'name', $name, '* '.l('name'), 'text', '', '', '', '', '', '', '', '', '');
$con_select .= html_input('text', 'position', 'position', $position, '* '.l('position'), 'text', '', '', '', '', '', '', '', '', '');
$con_select .= html_input('text', 'email', 'email', $email, '* '.l('email'), 'text', '', '', '', '', '', '', '', '', '');
$con_select .= html_input('text', 'roworder', 'roworder', $roworder, l('roworder'), 'text', '', '', '', '', '', '', '', '', '');
$con_select .= html_input('submit', 'add_contact', 'add_contact', l('add_contact'), '', 'button', '', '', '', '', '', '', '', '', '');
$con_select .= '</fieldset></form>';
if($cont_success=='yes'){$con_select .= contact_list(2);}
}
break;
case 5://contact update processing
$cont_query = $sql_all;
$cont_result = mysql_query($cont_query) or die('OOPS');
while ($r = mysql_fetch_array($cont_result)) {
$id= $r['id'];
$oldposition=$r['position'];$oldname=$r['name'];$oldemail=$r['email'];$oldrow=$r['roworder'];
$name = clean(cleanXSS($_POST['contact_edit'][$r['id']]['name']));
$position = clean(cleanXSS($_POST['contact_edit'][$r['id']]['position']));
$email = clean(cleanXSS($_POST['contact_edit'][$r['id']]['email']));
$roworder = clean(cleanXSS($_POST['contact_edit'][$r['id']]['roworder']));
if ($oldposition==$position){$pos_message = $position;}else{$pos_message = $oldposition.'/'.$position;}
if ($oldposition!=$position || $oldname!=$name || $oldemail!=$email || $oldrow!=$roworder)  {
mysql_query("UPDATE ".db('prefix')."contacts SET name = '$name', position = '$position', email = '$email', roworder = '$roworder' WHERE id = '$id' LIMIT 1;");
$con_select.='<p>You have just updated the contacts list for '.$pos_message.'</p>';
}}
$con_select.=contact_list(2);
break;
case 6://contact delete processing
$cont_query = $sql_6;
$cont_result = mysql_query($cont_query);
while ($r = mysql_fetch_array($cont_result)) {
if (clean(cleanXSS($_POST['contact_edit']['id']))=== $r['id']) {
$delete = $r['id'];
mysql_query("DELETE FROM ".db('prefix')."contacts WHERE id = $delete LIMIT 1;");
$con_select.='<p>'.l('delete_head').$r['name'].l('delete_tail').'</p>';
}
}
$con_select.=contact_list(2);
break;

// jlh add listing to contact_list Mod by philmoz
// case 7 is based on case 2

case 7:// contact display list in article
$cont_query = $sql_all;
$cont_result = mysql_query($cont_query) or die();
$con_select .= '<table id="contact_listing" >
<COLGROUP align="left"><COLGROUP align="left"><COLGROUP align="left">
<tr>
<th>'.l('contact_select_name').'</th><th>'.l('contact_select_position').'</th><th>'.l('contact_select_email').'</th></tr>';
while ($r = mysql_fetch_array($cont_result)) {
$alt = $alt == 0?1:0;$clss = $alt == 0?' class="contact_list_alt" ':'';
$con_select .= '<tr><td'.$clss.' >'.$r['name'].'</td> <td'.$clss.'>'.$r['position'].'</td><td'.$clss.'><a href="'.db('website'). 'contact/" >' . $r['email'] . ' </a></td></tr>';
}
$con_select.='</table>';
break;
// jlh add listing to contact_list Mod by philmoz


default:$con_select=contact_list(0);
}
}return $con_select;}

DEMO test / test

Hope this helps some one else. And thanks to philmoz for making this possible.
« Last Edit: September 23, 2008, 12:18:32 AM by jlhaslip »
Logged
Yes! I have no siggy.

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Create a Listing of Contacts inside an Article
« Reply #1 on: September 23, 2008, 01:01:15 AM »

Well done JH... this looks like it will be useful.  :)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Rui Mendes

  • Development,Testing, Support
  • Hero Member
  • *****
  • Karma: 195
  • Posts: 1009
  • sNews1.7
    • Comunidade Portuguesa
Re: Create a Listing of Contacts inside an Article
« Reply #2 on: September 23, 2008, 02:20:45 AM »

Good work jlhaslip. Congratulations. Karma 2U.

One opinion, I think you must add obfuscation function for plain text e-mail. See sNewsMU for details.

Quote
## MULTI_USER
function obfuscation($data) {
 $ret = '';
 for( $i=0; $i < strlen($data); ++$i ) {
   $r = rand(0,1);
   if( $r ) {
     $ret .= '&#x'. sprintf("%X",ord($data{$i})) . ';';
   }else{
     $ret .= '&#' . ord($data{$i}) . ';';
   }
 }
 return $ret;
}

Logged
Need a Job on Europe. Linkdin - Facebook / Group

jlhaslip

  • Sr. Member
  • ****
  • Karma: 16
  • Posts: 374
    • My snews with AEF Forum site
Re: Create a Listing of Contacts inside an Article
« Reply #3 on: September 23, 2008, 04:26:46 AM »

Yes, I have a function already written, just needing some time to get it into this script.
http://www.jlhaslip.trap17.com/samples/email/index.php
And I'll look at the one you suggest, too, for comparison.

*edit*
Code: [Select]
function hexentities($str) { // encodes the text
    global  $encoded;
    $encoded = '';
    for($i = 0; $i < strlen($str); $i++) {
        $encoded .= '&#x'.bin2hex(substr($str, $i, 1)).';';
    }
    return $encoded;
}
« Last Edit: September 23, 2008, 04:40:43 AM by jlhaslip »
Logged
Yes! I have no siggy.

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
Re: Create a Listing of Contacts inside an Article
« Reply #4 on: September 23, 2008, 03:33:25 PM »

well, looking at it, I would be tempted to make case 7 into a form, and instead of displaying email addresses, have form buttons(or radio buttons) (with names relating to contact id). Then work in the posting value to show the contact as selected in the contact form -- that way only the backend script handles the email addresses.

... but I do go overboard sometimes ;)
« Last Edit: September 23, 2008, 03:35:08 PM by philmoz »
Logged
Of all the things I have lost, it is my mind that I miss the most.

jlhaslip

  • Sr. Member
  • ****
  • Karma: 16
  • Posts: 374
    • My snews with AEF Forum site
Re: Create a Listing of Contacts inside an Article
« Reply #5 on: September 24, 2008, 05:00:31 AM »

Okay, I added that obfuscation function into the snew.php file and it works like it is supposed to, I guess.
Do a view source to check it out

Demo here
Logged
Yes! I have no siggy.

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
Re: Create a Listing of Contacts inside an Article
« Reply #6 on: September 24, 2008, 06:41:12 PM »

...sorry, just couldn't resist... :D :D

replaces the email address with radio button.
- this then automatically selects the person/position to recieve the message
 (using text links will only divert to the contact form (short of adding to url ?id='x').)

this doesn't have any radio's set as default
- if button pressed without radio selection, then regular contact form shown, no pre-selected recipient.

If radio selection made,
- select box is not shown, but is replaced with message indicating who will receive the message.

replace case 0
Code: [Select]
case 0 :// contacts pick list
if ($con_result<1 || (isset($_POST['on_contact_select'])&&is_array($_POST['aselect_contact']))){
if(is_array($_POST['aselect_contact'])){
$aselect_contact=$_POST['aselect_contact'];
$person_id = $aselect_contact[0] != ''?$aselect_contact[0]:0;
$display = retrieve($select_show,'contacts','id',$person_id);
/*Need lang var for this.*/ $con_select .= '<p><strong>Send message to '.$display.'.</strong></p>';}else{$person_id = 0;}
$con_select .= html_input('hidden', 'contact_person', 'contact_person', $person_id, '', '', '', '', '', '', '', '', '', '', '');}else{
$cont_query = $sql_0;
$cont_result = mysql_query($cont_query);
$con_select .= '<p><label for="contact_person">'.l('contact_person').'</label>:<br />';
$con_select .= '<select name="contact_person" id="cp">';
$con_select .= '<option value="0">'.l('general_contact').'</option>';
while ($r = mysql_fetch_array($cont_result)) {
$alt = $alt == 0?1:0;$clss = $alt == 1?' class="contact_list_op_alt" ':' class="contact_list_op_norm"';
$con_select.= '<option value="'.$r['id'].'"'.$clss.' >'.$r[$select_show].'</option>';
}
$con_select.='</select></p>';}
$con_select .= html_input('text', 'subject', 'subject', '', l('subject'), 'text', '', '', '', '', '', '', '', '', '');
break;
replace case 7
Code: [Select]
case 7:// contact display list in article
$cont_query = $sql_all;
$cont_result = mysql_query($cont_query) or die();
$con_select .= html_input('form', 'post', '', '', '', '', '', '', '', '', '', '', 'post', 'contact/', '');
$con_select .= '<table id="contact_listing" >
<COLGROUP align="left"><COLGROUP align="left"><COLGROUP align="left">
<tr>
<th></th><th>'.l('contact_select_name').'</th><th>'.l('contact_select_position').'</th></tr>';
while ($r = mysql_fetch_array($cont_result)) {
$alt = $alt == 0?1:0;$clss = $alt == 0?' class="contact_list_alt" ':'';
$clss2 = $clss!=''?explode('"',$clss):' class="radio" ';
if(is_array($clss2)){$clss2[1] = 'radio '.$clss2[1]; $clss2 =implode($clss2,'"');}
$con_select .= '<tr><td'.$clss.'><input type="radio" name="aselect_contact[]" value="'.$r['id'].'"></td><td'.$clss.' >'.$r['name'].'</td> <td'.$clss.'>'.$r['position'].'</td></tr>';
}
$con_select.='</table><input type="submit" name="on_contact_select" value="Contact"></form>';
break;
plus another style for styles.css
#contact_listing td.radio {
width:25px;
}
Should work ... caveat emptor ;)

« Last Edit: September 24, 2008, 10:26:46 PM by philmoz »
Logged
Of all the things I have lost, it is my mind that I miss the most.

jlhaslip

  • Sr. Member
  • ****
  • Karma: 16
  • Posts: 374
    • My snews with AEF Forum site
Re: Create a Listing of Contacts inside an Article
« Reply #7 on: September 24, 2008, 07:41:35 PM »

Options... always options...

thanks for the enhancements. Now the members will have several choices for the Listing.

K plus one to you.
Logged
Yes! I have no siggy.