| Server IP : 172.67.201.108 / Your IP : 216.73.217.85 Web Server : Apache/2.4.68 (Amazon Linux) OpenSSL/3.5.5 System : Linux ip-172-31-69-123.ec2.internal 6.1.176-223.369.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jul 24 13:34:27 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/mitzvahm/wwwdev/wp-content/plugins/lcs-project-db/ |
Upload File : |
<?php
/*
Plugin Name: LCS Project Database
Plugin URI: http://www.latcomsystems.com/
Description: Project Database module.
Version: 1.0
Author: LatCom Systems
Author URI: http://www.latcomsystems.com/
Copyright 2016 LatCom Systems
*/
define('AR_PROJECT_REGIONS', array('New York City','Long Island','Westchester/Rockland/Putnam','NY Metropolitan','New York - Other','New Jersey - Northern','New Jersey - Central','New Jersey - Southern/Philadelphia','Fairfield, CT','Nationwide','Mid-Atlantic','Southeast','MidWest','Rocky Mountains','Western US','Other'));
define('AR_PROJECT_CATEGORIES', array('Africa','Arts','Books','Bullying','Children','Community','Cooking','Dance','Education','Environmental','Fashion','Games','Health','Israel','Jewish Causes','Music','Recycle','Pets','Poverty','Seniors','Special Needs','Sports'));
define('AR_PROJECT_CONTRIBUTIONS', array('Services','Donations -Money only','Donations - Products/gifts'));
register_activation_hook(__FILE__, 'lcs_pdb_data_activation');
function lcs_pdb_data_activation()
{
global $wpdb;
global $db;
$upload_dir = wp_upload_dir();
$sql = "SELECT * FROM ".$wpdb->prefix."lcs_db_projects ";
$result = $db->query($sql) or die('Database Error!');
while ($row = $result->fetch(PDO::FETCH_OBJ)) :
if ($row->logo > ' ' && empty($row->logo_new)) :
$logo_clean = str_pad($row->id, 8, '0', STR_PAD_LEFT).'_'.str_replace(' ', '_', urldecode($row->logo));
$sql_update = "UPDATE ".$wpdb->prefix."lcs_db_projects SET logo_new = ".$db->quote($logo_clean)." WHERE id = ".nz($row->id, '0')." ";
$db->query($sql_update) or die('Database Error!');
file_put_contents($upload_dir['basedir'] . '/project_db/'.$logo_clean, $row->logo_blob);
endif;
if (empty($row->submitted_timestamp)) :
$sql_update = "UPDATE ".$wpdb->prefix."lcs_db_projects SET submitted_timestamp = '".date("Y-m-d H:i:s", $row->submit_time)."' WHERE id = ".nz($row->id, '0')." ";
$db->query($sql_update) or die('Database Error!');
endif;
if (empty($row->post_id)) :
$sql_key = "SELECT * FROM ".$wpdb->prefix."postmeta WHERE meta_key = 'titlekey' AND meta_value = ".$db->quote($row->meta_titlekey)." ";
$result_key = $db->query($sql_key) or die('Database Error!');
if ($result_key->rowCount() > 0) :
$row_key = $result_key->fetch(PDO::FETCH_OBJ);
$sql_update = "UPDATE ".$wpdb->prefix."lcs_db_projects SET post_id = ".nz($row_key->post_id, '0')." WHERE id = ".nz($row->id, '0')." ";
$db->query($sql_update) or die('Database Error!');
update_post_meta($row_key->post_id, 'lcs_project_id', $row->id);
endif;
endif;
endwhile;
}
register_deactivation_hook(__FILE__, 'lcs_pdb_data_deactivation');
function lcs_pdb_data_deactivation()
{
}
add_action('admin_menu', 'lcs_pdb_data_menu');
function lcs_pdb_data_menu()
{
add_menu_page(__('Project DB'), __('Project DB'), 'activate_plugins', 'lcs_pdb_data_admin', 'lcs_pdb_data_projects', 'dashicons-list-view', '26.5');
add_submenu_page('lcs_pdb_data_admin', __('Volunteer Projects'), __('Volunteer Projects'), 'activate_plugins', 'lcs_pdb_data_admin', 'lcs_pdb_data_projects');
add_submenu_page('lcs_pdb_data_admin', __('Options'), __('Options'), 'activate_plugins', 'lcs_pdb_data_options', 'lcs_pdb_data_options');
//add_submenu_page('lcs_lff_data_admin', __('Coupon Codes'), __('Coupon Codes'), 'activate_plugins', 'lcs_lff_data_coupon_codes', 'lcs_lff_data_coupon_codes');
//add_submenu_page('lcs_lff_data_admin', __('Exhibitors'), __('Exhibitors'), 'activate_plugins', 'lcs_lff_data_exhibitors', 'lcs_lff_data_exhibitors');
}
function lcs_pdb_data_options()
{
wp_enqueue_style( 'lcs-pdb-admin-style', plugins_url().'/lcs-project-db/lcs_project_db_admin.css', array(), filemtime(dirname(__FILE__).'/lcs_project_db_admin.css'));
global $wpdb;
global $db;
//$_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
$_POST = stripslashes_deep($_POST);
echo '<h1>Volunteer Project Form Options</h1>';
if ($_POST['lcs_pdb_submitted'] == '1') :
update_option('lcs_pdb_mail_to', $_POST['lcs_pdb_mail_to']);
update_option('lcs_pdb_mail_from', $_POST['lcs_pdb_mail_from']);
update_option('lcs_pdb_mail_subject', $_POST['lcs_pdb_mail_subject']);
update_option('lcs_pdb_mail_body', $_POST['lcs_pdb_mail_body']);
echo '<h2>Options saved.</h2>';
endif;
$_POST['lcs_pdb_mail_to'] = get_option('lcs_pdb_mail_to');
$_POST['lcs_pdb_mail_from'] = get_option('lcs_pdb_mail_from');
$_POST['lcs_pdb_mail_subject'] = get_option('lcs_pdb_mail_subject');
$_POST['lcs_pdb_mail_body'] = get_option('lcs_pdb_mail_body');
echo '<form method="post" action="" enctype="multipart/form-data">';
echo '<input type="hidden" name="lcs_pdb_submitted" value="1" />';
echo '<div class="input_column">';
form_field('lcs_pdb_mail_to', 'text', 75, 0, false, false, false, '', '', 'lcs_pdb_mail_to', 'Mail To');
form_field('lcs_pdb_mail_from', 'text', 75, 0, false, false, false, '', '', 'lcs_pdb_mail_from', 'Mail From');
form_field('lcs_pdb_mail_subject', 'text', 75, 0, false, false, false, '', '', 'lcs_pdb_mail_subject', 'Mail Subject');
form_field('lcs_pdb_mail_body', 'textarea', 70, 10, false, false, false, '', '', 'lcs_pdb_mail_body', 'Mail Body');
echo '</div>';
echo '<div class="clear_div"></div>';
echo '<input type="submit" name="submit" value="Save" />';
echo '</form>';
}
function lcs_pdb_data_projects()
{
wp_enqueue_style( 'lcs-pdb-admin-style', plugins_url().'/lcs-project-db/lcs_project_db_admin.css', array(), filemtime(dirname(__FILE__).'/lcs_project_db_admin.css'));
global $wpdb;
global $db;
if (empty($_GET['func'])) :
$_POST = stripslashes_deep($_POST);
$_GET = stripslashes_deep($_GET);
echo '<p><button onclick="window.location.href=\''.admin_url().'admin.php?page='.$_GET['page'].'&func=edit\';">Add New</button></p>';
$search_str = '';
if (!empty($_POST['search'])) :
$search_str_fields = 'post_title,post_content,post_status,street_add_1,street_add_2,city,state,zip_code,county,phone,website_url,contact_name,contact_title,contact_phone,contact_email,short_description,long_description,category,contribution';
$search_int_fields = '';
$search_str = lcs_search_tokenize($search_str_fields, $search_int_fields, $_POST['search']);
endif;
$sql = "SELECT *, NULL AS logo_blob FROM ".$wpdb->prefix."lcs_db_projects ".$search_str." ORDER BY submitted_timestamp DESC";
//echo '<p>'.$sql.'</p>';
lcs_pdb_data_panel('Data Administration - Volunteer Projects', $sql, array('post_title'=>'lcs_pdb_data_projects_sub', 'submit_time'=>'lcs_pdb_data_projects_sub'));
elseif ($_GET['func'] == 'edit') :
$_POST = array_map_r('strip_tags', $_POST);
$_POST = stripslashes_deep($_POST);
//var_dump_pre($_POST);
$current_user = wp_get_current_user();
$cat_id = get_cat_ID('Volunteer Projects');
$upload_dir = wp_upload_dir();
//var_dump_pre($cat_id);
if (empty($_REQUEST['id'])) :
$action = 'add';
echo '<h1>Volunteer Project - Add New</h1>';
$logo_file_id = next_id($wpdb->prefix."lcs_db_projects");
if (empty($_POST['lcs_pdb_submitted'])) :
/*
$_POST['active'] = '1' ;
$_POST['show_year'] = get_option('lff_exhibitor_current_show_year');
$_POST['region'] = get_option('lff_exhibitor_current_region');
*/
endif;
else :
$action = 'edit';
$sql = "SELECT * FROM ".$wpdb->prefix."lcs_db_projects WHERE id = ".nz($_REQUEST['id'], '0');
$result = $db->query($sql) or die('Database Error!');
if ($result->rowCount() > 0) :
$row = $result->fetch(PDO::FETCH_OBJ);
echo '<h1>Volunteer Project - Edit - '.$row->post_title.'</h1>';
if (empty($_POST['lcs_pdb_submitted'])) :
foreach ($row as $key => $value) :
$_POST[$key] = $value;
endforeach;
endif;
$logo_file_id = $row->id;
else :
echo '<h1>Invalid Operation!</h1>';
return;
endif;
endif;
global $ar_err;
global $err_flag;
$ar_err = array();
if ($_POST['lcs_pdb_submitted'] == '1') :
//var_dump_pre($_POST);
form_validate('post_title', 'string', true);
form_validate('post_status', 'string', true);
form_validate('street_add_1', 'string', true);
form_validate('city', 'string', false);
form_validate('state', 'string', false);
form_validate('zip_code', 'string', false);
form_validate('phone', 'string', true);
form_validate('contact_name', 'string', true);
form_validate('contact_phone', 'string', true);
form_validate('contact_email', 'string', true);
form_validate('county', 'string', true);
form_validate('category', 'string', true);
form_validate('contribution', 'string', true);
form_validate('short_description', 'string', true);
form_validate('long_description', 'string', true);
if (!$err_flag) :
/* ***************** store photos **************** */
//var_dump($_FILES);
if (isset($_FILES['filename'])) :
$check = getimagesize($_FILES['filename']['tmp_name']);
if($check !== false) :
$target_dir = $upload_dir['basedir'] . '/project_db/';
$ext = strtolower(pathinfo($_FILES['filename']['name'],PATHINFO_EXTENSION));
if ($ext == 'jpg' || $ext == 'jpeg' || $ext == 'png' || $ext == 'gif') :
$max_dim = 800;
list($img_width, $img_height, $_img_type, $img_attr) = $check;
//$file_id = bin2hex(openssl_random_pseudo_bytes(12)).'.'.$ext;
$file_id = str_pad($logo_file_id, 8, '0', STR_PAD_LEFT).'_'.str_replace(' ', '_', $_FILES['filename']['name']);
$source = $_FILES['filename']['tmp_name'];
$dest = $target_dir.basename($file_id);
$ratio = $img_width/$img_height; // width/height
if ( $img_width > $max_dim || $img_height > $max_dim ) :
if( $ratio > 1) :
$new_width = $max_dim;
$new_height = $max_dim / $ratio;
else :
$new_width = $max_dim * $ratio;
$new_height = $max_dim;
endif;
else :
$new_width = $img_width;
$new_height = $img_height;
endif;
$src = imagecreatefromstring( file_get_contents( $source ) );
$dst = imagecreatetruecolor( $new_width, $new_height );
imagecopyresampled( $dst, $src, 0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height );
imagedestroy( $src );
switch($ext){
case "gif":
$image_result = imagegif( $dst, $dest );
break;
case "jpg":
$image_result = imagejpeg( $dst, $dest );
break;
case "jpeg":
$image_result = imagejpeg( $dst, $dest );
break;
case "png":
$image_result = imagepng( $dst, $dest );
break;
}
imagedestroy( $dst );
//echo ' === source: '.$source.' === dest: '.$dest.' === ';
//if (move_uploaded_file($source, $dest)) :
if ($image_result) :
$_POST['logo_new'] = $file_id;
else :
die('Error uploading file ');
endif;
else :
$ar_err['filename'] = 'Invalid image file extension!';
$err_flag = true;
endif;
else :
if (!empty($_FILES['filename']['tmp_name'])) :
$ar_err['filename'] = 'File to upload is not an image!';
$err_flag = true;
endif;
endif;
else :
/*
if ($action != "Edit") :
$ar_err['filename'] = 'Photo to upload is required!';
$err_flag = true;
$err_tab = 'basic_info';
endif;
*/
endif;
/* ************************************************ */
if (!$err_flag) :
if ($action == 'edit' && !empty($_POST['post_id'])) :
$ar_post = array(
'ID' => trim($_POST['post_id']),
'post_title' => trim($_POST['post_title']),
'post_content' => (trim($_POST['short_description'])),
'post_status' => trim($_POST['post_status']),
'post_date' => date('Y-m-d H:i:s'),
'post_author' => trim($current_user->user_login),
'post_type' => 'post',
'post_category' => array($cat_id),
);
wp_update_post($ar_post);
update_post_meta(trim($_POST['post_id']), 'lcs_project_id', $_POST['id']);
if (!empty($_POST['logo_new'])) :
update_post_meta(trim($_POST['post_id']), 'image', $upload_dir['basedir'] . '/project_db/'.$_POST['logo_new']);
endif;
elseif ($action == 'add') :
$ar_post = array(
'post_title' => trim($_POST['post_title']),
'post_content' => (trim($_POST['short_description'])),
'post_status' => trim($_POST['post_status']),
'post_date' => date('Y-m-d H:i:s'),
'post_author' => trim($current_user->user_login),
'post_type' => 'post',
'post_category' => array($cat_id),
);
$_POST['post_id'] = wp_insert_post($ar_post);
endif;
$set = "post_title = ".$db->quote(trim($_POST['post_title'])).", ".
"post_status = ".$db->quote(trim($_POST['post_status'])).", ".
"street_add_1 = ".$db->quote(trim($_POST['street_add_1'])).", ".
"street_add_2 = ".$db->quote(trim($_POST['street_add_2'])).", ".
"city = ".$db->quote(trim($_POST['city'])).", ".
"state = ".$db->quote(trim($_POST['state'])).", ".
"zip_code = ".$db->quote(trim($_POST['zip_code'])).", ".
"country = ".$db->quote(trim($_POST['country'])).", ".
"phone = ".$db->quote(trim($_POST['phone'])).", ".
"website_url = ".$db->quote(trim($_POST['website_url'])).", ".
"contact_name = ".$db->quote(trim($_POST['contact_name'])).", ".
"contact_title = ".$db->quote(trim($_POST['contact_title'])).", ".
"contact_phone = ".$db->quote(trim($_POST['contact_phone'])).", ".
"contact_email = ".$db->quote(trim($_POST['contact_email'])).", ".
"county = ".$db->quote(trim($_POST['county'])).", ".
"category = ".$db->quote(trim($_POST['category'])).", ".
"contribution = ".$db->quote(trim($_POST['contribution'])).", ".
"short_description = ".$db->quote(trim($_POST['short_description'])).", ".
"long_description = ".$db->quote(trim($_POST['long_description'])).", ".
"mitzvah_bowl = ".nz($_POST['mitzvah_bowl'], '0').", ".
"logo_new = ".$db->quote(trim($_POST['logo_new'])).", ".
"post_id = ".nz($_POST['post_id'], '0').", ".
"update_timestamp = ".$db->quote(date('Y-m-d H:i:s')).", ".
"update_by = ".$db->quote(trim($current_user->user_login))." ";
if ($action == 'edit') :
$sql = "UPDATE ".$wpdb->prefix."lcs_db_projects SET ".$set.
"WHERE id = ".nz($_REQUEST['id'], '0')." ";
$db->query($sql) or die('Database Error!');
//echo '==='.$sql.'===';
$_POST['update_by'] = trim($current_user->user_login);
$_POST['update_timestamp'] = date('m/d/Y h:i:s a');
if (!empty($_POST['logo_new'])) :
update_post_meta(trim($_POST['post_id']), 'image', $upload_dir['baseurl'] . '/project_db/'.$_POST['logo_new']);
endif;
else :
if ($action == 'add') :
$sql = "INSERT INTO ".$wpdb->prefix."lcs_db_projects SET ".
"submitted_timestamp = ".$db->quote(date('Y-m-d H:i:s')).", ".
"create_timestamp = ".$db->quote(date('Y-m-d H:i:s')).", ".
"create_by = ".$db->quote(trim($current_user->user_login)).", ".
$set;
//echo '==='.$sql.'===';
$db->query($sql) or die('Database Error!');
$_POST['id'] = last_id();
$_POST['create_by'] = trim($current_user->user_login);
$_POST['create_timestamp'] = date('m/d/Y h:i:s a');
$_POST['update_by'] = trim($current_user->user_login);
$_POST['update_timestamp'] = date('m/d/Y h:i:s a');
update_post_meta(trim($_POST['post_id']), 'lcs_project_id', $_POST['id']);
if (!empty($_POST['logo_new'])) :
update_post_meta(trim($_POST['post_id']), 'image', $upload_dir['baseurl'] . '/project_db/'.$_POST['logo_new']);
endif;
endif;
endif;
echo '<h2 class="form_ok">Saved Succesfully!</h2>';
if ($_POST['submit'] == 'Save & New') :
echo '<script>';
echo 'window.location.href="'.site_url().'/wp-admin/admin.php?page=lcs_pdb_data_admin&func=edit";';
echo '</script>';
return;
elseif ($_POST['submit'] == 'Save & Close') :
echo '<script>';
echo 'window.location.href="'.site_url().'/wp-admin/admin.php?page=lcs_pdb_data_admin";';
echo '</script>';
return;
endif;
else :
echo '<h2 class="form_error">Errors found!</h2>';
endif;
else :
echo '<h2 class="form_error">Errors found!</h2>';
endif;
else :
endif;
//var_dump_pre($current_user);
echo '<form method="post" action="" enctype="multipart/form-data">';
echo '<input type="hidden" name="lcs_pdb_submitted" value="1" />';
echo '<input type="hidden" name="post_id" value="'.$_POST['post_id'].'" />';
echo '<div class="input_column">';
form_field('id', 'text', 10, 0, false, false, true, '', '', 'id', 'Project ID');
form_field('post_title', 'text', 75, 0, true, false, false, '', '', 'post_title', 'Project Title');
form_field('post_status', 'radiogroup', 50, 0, true, false, false, '', '', 'post_status', 'Status', array('draft', 'publish'));
form_field('street_add_1', 'text', 75, 0, true, false, false, '', '', 'street_add_1', 'Street Address');
form_field('street_add_2', 'text', 75, 0, false, false, false, '', '', 'street_add_2', '');
form_field('city', 'text', 75, 0, false, false, false, '', '', 'city', 'City');
$sql = "SELECT state, state_name FROM ".$wpdb->prefix."lcs_states WHERE country_sort_code = 1 ORDER BY state_name ";
$result = $db->query($sql) or die('Database Error!');
$ar_states = $result->fetchAll(PDO::FETCH_KEY_PAIR);
form_field('state', 'select', 25, 0, false, false, false, '', '', 'state', 'State', $ar_states);
form_field('zip_code', 'text', 25, 0, false, false, false, '', '', 'zip_code', 'Zip Code');
form_field('country', 'text', 50, 0, false, false, false, '', '', 'country', 'Country');
form_field('phone', 'text', 25, 0, true, false, false, '', '', 'phone', 'Phone');
form_field('website_url', 'text', 100, 0, false, false, false, '', '', 'website_url', 'Website URL');
form_field('contact_name', 'text', 100, 0, true, false, false, '', '', 'contact_name', 'Contact Name');
form_field('contact_title', 'text', 100, 0, false, false, false, '', '', 'contact_title', 'Contact Title');
form_field('contact_phone', 'text', 25, 0, true, false, false, '', '', 'contact_phone', 'Contact Phone');
form_field('contact_email', 'text', 100, 0, true, false, false, '', '', 'contact_email', 'Contact Email');
echo '</div>';
echo '<div class="input_column">';
form_field('county', 'select', 75, 0, true, false, false, '', '', 'county', 'Location', AR_PROJECT_REGIONS);
form_field('category', 'select', 50, 0, true, false, false, '', '', 'category', 'Category', AR_PROJECT_CATEGORIES);
form_field('contribution', 'select', 50, 0, true, false, false, '', '', 'contribution', 'Contribution', AR_PROJECT_CONTRIBUTIONS);
form_field('mitzvah_bowl', 'checkbox', 50, 0, false, false, false, '', '', 'mitzvah_bowl', 'Mitzvah Bowl');
form_field('short_description', 'textarea', 70, 8, true, false, false, '', '', 'short_description', 'Short Description (25 words or less)');
form_field('long_description', 'textarea', 70, 12, true, false, false, '', '', 'long_description', 'Long Description');
echo '</div>';
echo '<div class="input_column">';
echo '<div class="input_field">';
echo '<label for="photo_label">Photo</label>';
echo '<label id="photo_label" class="photo_label" for="filename">';
echo 'Click/Touch here to upload or snap a photo<br />';
echo '<input name="filename" id="filename" type="file" maxlength="120" accept="image/*" capture="camera" />';
echo '</label>';
echo '<input name="logo_new" type="hidden" maxlength="120" value="'.$_POST['logo_new'].'" />';
show_form_error2($ar_err['filename']);
echo '</div>';
if (!empty($_POST['logo_new'])) :
echo '<br />';
echo '<div style="width:100%; max-width:750px; text-align:center; margin-left:auto; margin-right:auto;">';
echo '<img src="'.$upload_dir['baseurl'] . '/project_db/'.$_POST['logo_new'].'" style="max-width:100%;" align="top" />';
echo '</div>';
endif;
form_field('create_timestamp', 'text', 50, 0, false, false, true, '', '', 'create_timestamp', 'Date Created');
form_field('create_by', 'text', 50, 0, false, false, true, '', '', 'create_by', 'Created By');
form_field('update_timestamp', 'text', 50, 0, false, false, true, '', '', 'update_timestamp', 'Date Updated');
form_field('update_by', 'text', 50, 0, false, false, true, '', '', 'update_by', 'Updated By');
echo '</div>';
echo '<div class="clear_div"></div>';
echo '<input type="submit" name="submit" value="Save" />';
echo ' <input type="submit" name="submit" value="Save & New" />';
echo ' <input type="submit" name="submit" value="Save & Close" />';
echo ' <input type="button" value="Cancel" onclick="window.location.href=\''.site_url().'/wp-admin/admin.php?page=lcs_pdb_data_admin\';" />';
echo '</form>';
//var_dump_pre($_POST);
endif;
}
function lcs_pdb_data_projects_sub($value, $row, $field_name)
{
global $db;
global $wpdb;
$retval = '';
switch ($field_name) :
case 'post_title' :
if ($_POST['lcs_pdb_submitted'] == 2) :
$sql = "SELECT * FROM ".$wpdb->prefix."lcs_db_projects WHERE id = ".nz($_POST['id']);
$result = $db->query($sql) or die('Database Error!');
if ($result->rowCount() > 0) :
$row = $result->fetch(PDO::FETCH_OBJ);
wp_delete_post($row->post_id, true);
endif;
$sql = "DELETE FROM ".$wpdb->prefix."lcs_db_projects WHERE id = ".nz($_POST['id']);
$db->query($sql) or die('Database Error!');
echo '<script>';
echo 'window.location.href = "'.$_SERVER['REQUEST_URI'].'"';
echo '</script>';
exit();
endif;
$retval .= '<a href="'.site_url().'/wp-admin/admin.php?page=lcs_pdb_data_admin&func=edit&id='.$row->id.'">'.$value.'</a><br /><br />';
$retval .= '<form action="" method="post" onsubmit="return confirm(\'Are you sure?\');">';
$retval .= '<input type="hidden" name="lcs_pdb_submitted" value="2" />';
$retval .= '<input type="hidden" name="id" value="'.$row->id.'" />';
$retval .= '<input type="submit" name="submit" value="Delete" /><br />';
$retval .= '</form>';
break;
case 'submit_time' :
$retval = date("Y-m-d H:i:s",$value);
break;
endswitch;
return $retval;
}
function lcs_search_tokenize($str_fields, $int_fields, $search)
{
global $db;
$result = '';
$ar_result = array();
if (!empty($str_fields)) :
$search_str = $db->quote('%'.$search.'%');
$ar_str = explode(',', $str_fields);
foreach ($ar_str as $field) :
$ar_result[] = " ".$field." LIKE ".$search_str." ";
endforeach;
endif;
if (!empty($int_fields)) :
$search_int = nz($search, '0');
$ar_int = explode(',', $int_fields);
foreach ($ar_int as $field) :
$ar_result[] = " ".$field." = ".$search_int." ";
endforeach;
endif;
$result = implode(" OR ", $ar_result);
if (!empty($result)) :
$result = " WHERE ".$result;
endif;
return $result;
}
function lcs_pdb_data_panel($title, $sql, $ar_funcs = array())
{
global $db;
global $wpdb;
$excel_url = site_url() . '/wp-content/plugins/' . "lcs-project-db" . '/export_excel.php';
//echo '<p>SQL: '.$sql.'</p>';
if (empty($_SESSION['lcs_rand_key'])) :
$_SESSION['lcs_rand_key'] = generate_random_string(32);
endif;
echo '<h1>'.$title.'</h1>';
$result = $db->query($sql) or die('Database Error!');
if ($result->rowCount() > 0) :
//echo '<p>';
echo '<style>';
echo 'form {display:inline-block;}';
echo 'table.lcs_data_table td {vertical-align:top;}';
echo '</style>';
echo '<div>';
echo $result->rowCount().' records found. ';
echo '<button onclick="exportExcel(\''.urlencode(lcs_pdb_sys_encrypt(gzcompress($sql,6), $_SESSION['lcs_rand_key'])).'\')">Export to Excel®</button>';
//echo '<p>SQL: '.$sql.'</p>';
echo ' Search: <form method="post" action="">';
echo '<input type="text" class="search" name="search" value="'.stripslashes_deep($_POST['search']).'" />';
echo '<input type="submit" name="submit" value="Find" />';
echo '</form>';
echo ' <button onclick="window.location.href=window.location.href">List All</button>';
echo '</div>';
echo '<br /><br />';
//echo '</p>';
echo '<table class="lcs_data_table" style="border-collapse:collapse; border:1px solid #000000;">';
echo '<thead><tr>';
$ar_field_types = array();
$ar_field_names = array();
$i = 0;
while ($i < $result->columnCount()) :
$meta = $result->getColumnMeta($i);
if (!$meta) :
$ar_field_types[$i] = 'string';
$column_name = 'column_'.$i;
else :
$ar_field_types[$i] = strtolower($meta['native_type']);
$column_name = $meta['name'];
endif;
$ar_field_names[$i] = $column_name;
echo '<th style="border:1px solid #000000; padding:5px;">'.$column_name.'</th>';
//echo '<th style="border:1px solid #000000; padding:5px;">'.$column_name.' - '.$ar_field_types[$i].'</th>';
$i++;
endwhile;
echo '</tr></thead>';
while ($row = $result->fetch(PDO::FETCH_OBJ)) :
echo '<tr>';
$curr_col = 0;
foreach($row as $row_field) :
$row_field = utf8_encode($row_field);
$value = '';
if ($ar_field_types[$curr_col] == 'long' || $ar_field_types[$curr_col] == 'longlong') :
$align = 'right';
$value = intval(html_entity_decode($row_field, ENT_QUOTES));
elseif ($ar_field_types[$curr_col] == 'newdecimal' || $ar_field_types[$curr_col] == 'float') :
$align = 'right';
$value = number_format(floatval(html_entity_decode($row_field, ENT_QUOTES)), 2, '.', ',');
else :
$align = 'left';
$value = trim(html_entity_decode($row_field, ENT_QUOTES));
$link_value = $value;
if (strlen($value) > 100) :
$value = substr($value, 0, 100).'...';
endif;
if (strtolower(substr($row_field,0,7)) == 'http://' || strtolower(substr($row_field,0,8)) == 'https://') :
$value = '<a target="_blank" href="'.$link_value.'">'.$value.'</a>';
endif;
endif;
if (!empty($ar_funcs[$ar_field_names[$curr_col]])) :
$value = $ar_funcs[$ar_field_names[$curr_col]]($value, $row, $ar_field_names[$curr_col]);
endif;
echo '<td style="border:1px solid #000000; padding:5px;" align="'.$align.'">'.$value.'</td>';
$curr_col = $curr_col + 1;
endforeach;
echo '</tr>';
endwhile;
echo '</table>';
?>
<script>
exportExcel = function(xls_sql)
{
window.location.href = "<?php echo $excel_url; ?>?sql=" + xls_sql;
//rptWindowName = this.open("<?php echo $excel_url; ?>?sql=" + xls_sql, "rptWindowName", "scrollbars=yes, resizable=yes, location=no, toolbar=no, menubar=no");
//rptWindowName.focus();
}
</script>
<?php
else :
echo '<p>No records found.</p>';
echo '<button onclick="window.location.href=window.location.href">List All</button>';
endif;
}
add_shortcode( 'lcs_form_new_project', 'lcs_form_new_project' );
function lcs_form_new_project() {
//ini_set('display_errors', true);
global $wpdb;
global $db;
$signed_up = false;
$out = '';
ob_start();
$_POST = array_map_r('strip_tags', $_POST);
$_POST = stripslashes_deep($_POST);
$current_user = wp_get_current_user();
$cat_id = get_cat_ID('Volunteer Projects');
$upload_dir = wp_upload_dir();
//var_dump_pre($cat_id);
global $ar_err;
global $err_flag;
$logo_file_id = next_id($wpdb->prefix."lcs_db_projects");
$ar_err = array();
if (isset($_POST['captcha'])) :
$captcha = strtolower($_POST['captcha']);
else :
$captcha = '';
endif;
if (isset($_SESSION['captcha_key'])) :
$captcha_key = strtolower($_SESSION['captcha_key']);
else :
$captcha_key = 'fdsdjas125sdudklsafjdfjfjsffflf';
endif;
//var_dump_pre($captcha_key);
if ($_POST['lcs_pdb_submitted'] == '1') :
//var_dump_pre($_POST);
form_validate('post_title', 'string', true);
form_validate('street_add_1', 'string', true);
form_validate('city', 'string', true);
if (empty($_POST['country']) || (substr(strtoupper($_POST['country']), 0, 2) == 'US') || (substr(strtoupper($_POST['country']), 0, 13) == 'UNITED STATES')) :
form_validate('state', 'string', true);
form_validate('zip_code', 'string', true);
$js_string .= '$("#country").removeClass("required")';
else :
$js_string .= '$("#state, #zip_code").removeClass("required")';
endif;
form_validate('phone', 'string', true);
form_validate('contact_name', 'string', true);
form_validate('contact_phone', 'string', true);
form_validate('contact_email', 'email', true);
form_validate('county', 'string', true);
form_validate('category', 'string', true);
form_validate('contribution', 'string', true);
form_validate('short_description', 'string', true);
form_validate('long_description', 'string', true);
if ($captcha_key != md5($captcha)):
$ar_err['captcha'] = 'Verification invalid!';
$err_flag = true;
endif;
if (!$err_flag) :
/* ***************** store photos **************** */
//var_dump($_FILES);
if (isset($_FILES['filename'])) :
$check = getimagesize($_FILES['filename']['tmp_name']);
if($check !== false) :
$target_dir = $upload_dir['basedir'] . '/project_db/';
$ext = strtolower(pathinfo($_FILES['filename']['name'],PATHINFO_EXTENSION));
if ($ext == 'jpg' || $ext == 'jpeg' || $ext == 'png' || $ext == 'gif') :
$max_dim = 800;
list($img_width, $img_height, $_img_type, $img_attr) = $check;
//$file_id = bin2hex(openssl_random_pseudo_bytes(12)).'.'.$ext;
$file_id = str_pad($logo_file_id, 8, '0', STR_PAD_LEFT).'_'.str_replace(' ', '_', $_FILES['filename']['name']);
$source = $_FILES['filename']['tmp_name'];
$dest = $target_dir.basename($file_id);
$ratio = $img_width/$img_height; // width/height
if ( $img_width > $max_dim || $img_height > $max_dim ) :
if( $ratio > 1) :
$new_width = $max_dim;
$new_height = $max_dim / $ratio;
else :
$new_width = $max_dim * $ratio;
$new_height = $max_dim;
endif;
else :
$new_width = $img_width;
$new_height = $img_height;
endif;
$src = imagecreatefromstring( file_get_contents( $source ) );
$dst = imagecreatetruecolor( $new_width, $new_height );
imagecopyresampled( $dst, $src, 0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height );
imagedestroy( $src );
switch($ext){
case "gif":
$image_result = imagegif( $dst, $dest );
break;
case "jpg":
$image_result = imagejpeg( $dst, $dest );
break;
case "jpeg":
$image_result = imagejpeg( $dst, $dest );
break;
case "png":
$image_result = imagepng( $dst, $dest );
break;
}
imagedestroy( $dst );
//echo ' === source: '.$source.' === dest: '.$dest.' === ';
//if (move_uploaded_file($source, $dest)) :
if ($image_result) :
$_POST['logo_new'] = $file_id;
else :
die('Error uploading file ');
endif;
else :
$ar_err['filename'] = 'Invalid image file extension!';
$err_flag = true;
endif;
else :
if (!empty($_FILES['filename']['tmp_name'])) :
$ar_err['filename'] = 'File to upload is not an image!';
$err_flag = true;
endif;
endif;
else :
/*
if ($action != "Edit") :
$ar_err['filename'] = 'Photo to upload is required!';
$err_flag = true;
$err_tab = 'basic_info';
endif;
*/
endif;
/* ************************************************ */
if (!$err_flag) :
$db->beginTransaction();
$ar_post = array(
'post_title' => trim($_POST['post_title']),
'post_content' => (trim($_POST['short_description'])),
'post_status' => 'draft',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => trim($current_user->user_login),
'post_type' => 'post',
'post_category' => array($cat_id),
);
$post_id = wp_insert_post($ar_post);
$set = "post_title = ".$db->quote(trim($_POST['post_title'])).", ".
"post_status = 'draft', ".
"street_add_1 = ".$db->quote(trim($_POST['street_add_1'])).", ".
"street_add_2 = ".$db->quote(trim($_POST['street_add_2'])).", ".
"city = ".$db->quote(trim($_POST['city'])).", ".
"state = ".$db->quote(trim($_POST['state'])).", ".
"zip_code = ".$db->quote(trim($_POST['zip_code'])).", ".
"country = ".$db->quote(trim($_POST['country'])).", ".
"phone = ".$db->quote(trim($_POST['phone'])).", ".
"website_url = ".$db->quote(trim($_POST['website_url'])).", ".
"contact_name = ".$db->quote(trim($_POST['contact_name'])).", ".
"contact_title = ".$db->quote(trim($_POST['contact_title'])).", ".
"contact_phone = ".$db->quote(trim($_POST['contact_phone'])).", ".
"contact_email = ".$db->quote(trim($_POST['contact_email'])).", ".
"county = ".$db->quote(trim($_POST['county'])).", ".
"category = ".$db->quote(trim($_POST['category'])).", ".
"contribution = ".$db->quote(trim($_POST['contribution'])).", ".
"short_description = ".$db->quote(trim($_POST['short_description'])).", ".
"long_description = ".$db->quote(trim($_POST['long_description'])).", ".
"mitzvah_bowl = ".nz($_POST['mitzvah_bowl'], '0').", ".
"logo_new = ".$db->quote(trim($_POST['logo_new'])).", ".
"post_id = ".nz($post_id, '0').", ".
"submitted_timestamp = ".$db->quote(date('Y-m-d H:i:s')).", ".
"submitted_by = ".$db->quote(trim($current_user->user_login)).", ".
"submitted_ip = ".$db->quote(get_client_ip())." ";
$sql = "INSERT INTO ".$wpdb->prefix."lcs_db_projects SET ".
$set;
//echo '==='.$sql.'===';
$db->query($sql) or die('Database Error!');
$last_id = last_id();
update_post_meta($post_id, 'lcs_project_id', $last_id);
if (!empty($_POST['logo_new'])) :
update_post_meta($post_id, 'image', $upload_dir['baseurl'] . '/project_db/'.$_POST['logo_new']);
endif;
//******* mail using PEAR ********
/*
*/
require_once "Mail.php";
$mail_body = '<html>'.
'<style>body {font-family:Arial, Helvetica, sans-serif; font-size:14px;} table {font-size:14px;}</style>'.
nl2br(lcs_pdb_parse_placeholders(get_option('lcs_pdb_mail_body'))).
'</html>' ;
$pmail_from = lcs_pdb_parse_placeholders(get_option('lcs_pdb_mail_from'));
$pmail_to["To"] = lcs_pdb_parse_placeholders(get_option('lcs_pdb_mail_to'));
//$pmail_to["Bcc"] = get_option('woo_lcs_mb_bcc');
$pmail_subject = lcs_pdb_parse_placeholders(get_option('lcs_pdb_mail_subject'));
$pmail_body = $mail_body;
$pmail_host = get_cfg_var('SMTP');
$pmail_username = "";
$pmail_password = "";
$pmail_headers = array ('From' => $pmail_from,
'To' => $pmail_to["To"],
'Subject' => $pmail_subject,
'MIME-Version' => '1.0',
'Content-type' => 'text/html; charset=iso-8859-1');
$smtp = Mail::factory('smtp',
array ('host' => $pmail_host,
//'auth' => true,
'auth' => false,
'username' => $pmail_username,
'password' => $pmail_password
));
$pmail = $smtp->send($pmail_to, $pmail_headers, $pmail_body);
if (PEAR::isError($pmail)) :
echo '<h2 class="form_error">Error! Unable to send email. Please contact us.</h2>';
//echo $pmail->getMessage();
$db->rollBack();
else :
$db->commit();
echo '<h2 class="form_ok">Submitted Succesfully!</h2>';
$signed_up = true;
echo '<script>';
echo 'setTimeout(function() {window.location.href="'.site_url().'"; }, 1000);';
echo '</script>';
endif;
else :
echo '<h2 class="form_error">Errors found!</h2>';
endif;
else :
echo '<h2 class="form_error">Errors found!</h2>';
endif;
else :
endif;
//var_dump_pre($current_user);
if (!$signed_up) :
echo '<div class="project_form">';
echo '<form method="post" action="" enctype="multipart/form-data">';
echo '<input type="hidden" name="lcs_pdb_submitted" value="1" />';
echo '<input type="hidden" name="post_id" value="'.$_POST['post_id'].'" />';
echo '<div class="input_column">';
form_field('post_title', 'text', 75, 0, true, false, false, '', '', 'post_title', 'Organization Name');
form_field('street_add_1', 'text', 75, 0, true, false, false, '', '', 'street_add_1', 'Street Address');
form_field('street_add_2', 'text', 75, 0, false, false, false, '', '', 'street_add_2', '');
form_field('city', 'text', 75, 0, true, false, false, '', '', 'city', 'City');
$sql = "SELECT state, state_name FROM ".$wpdb->prefix."lcs_states WHERE country_sort_code = 1 ORDER BY state_name ";
$result = $db->query($sql) or die('Database Error!');
$ar_states = $result->fetchAll(PDO::FETCH_KEY_PAIR);
form_field('state', 'select', 25, 0, true, false, false, '', '', 'state', 'State', $ar_states);
form_field('zip_code', 'text', 25, 0, true, false, false, '', '', 'zip_code', 'Zip Code');
form_field('country', 'text', 50, 0, true, false, false, '', '', 'country', 'Country');
form_field('phone', 'text', 25, 0, true, false, false, '', '', 'phone', 'Phone');
form_field('website_url', 'text', 100, 0, false, false, false, '', '', 'website_url', 'Website URL');
form_field('contact_name', 'text', 100, 0, true, false, false, '', '', 'contact_name', 'Contact Name');
form_field('contact_title', 'text', 100, 0, false, false, false, '', '', 'contact_title', 'Contact Title');
form_field('contact_phone', 'text', 25, 0, true, false, false, '', '', 'contact_phone', 'Contact Phone');
form_field('contact_email', 'text', 100, 0, true, false, false, '', '', 'contact_email', 'Contact Email');
form_field('county', 'select', 75, 0, true, false, false, '', '', 'county', 'Location', AR_PROJECT_REGIONS);
echo '</div>';
echo '<div class="input_column">';
form_field('category', 'select', 50, 0, true, false, false, '', '', 'category', 'Category', AR_PROJECT_CATEGORIES);
form_field('contribution', 'select', 50, 0, true, false, false, '', '', 'contribution', 'Contribution', AR_PROJECT_CONTRIBUTIONS);
form_field('short_description', 'textarea', 70, 8, true, false, false, '', '', 'short_description', 'Short Description of Your Organization (25 words or less)');
form_field('long_description', 'textarea', 70, 12, true, false, false, '', '', 'long_description', 'Full Description of Your Organization');
form_field('mitzvah_bowl', 'checkbox', 50, 0, false, false, false, '', '', 'mitzvah_bowl', 'Mitzvah Bowl');
/* **** Image upload *** */
echo '<div class="input_field">';
echo '<label for="photo_label">Photo</label>';
echo '<label id="photo_label" class="photo_label" for="filename">';
echo 'Click/Touch here to upload or snap a photo<br />';
echo '<input name="filename" id="filename" type="file" maxlength="120" accept="image/*" capture="camera" />';
echo '</label>';
echo '<input name="logo_new" type="hidden" maxlength="120" value="'.$_POST['logo_new'].'" />';
show_form_error($ar_err['filename']);
echo '</div>';
/* **** CAPTCHA *****/
echo '<div style="width:40%; min-width:100px; display:inline-block; margin-right:1%;">';
form_field('captcha', 'text', 15, 0, true, false, false, '', '', 'captcha', 'Verification Code');
echo '</div>';
echo '<div style="width:55%; min-width:150px; display:inline-block; vertical-align:top; margin-top:25px;">';
echo '<img id="project_captcha" class="captcha" style="vertical-align:middle; width:130px; height:30px;" align="middle" src="'.get_bloginfo('stylesheet_directory').'/captcha.php" /> ';
echo '<img style="vertical-align:middle; cursor:pointer;" class="captcha-reset" align="middle" src="'.get_bloginfo('stylesheet_directory').'/images/reload.png" onclick="reload_captcha(\'project_captcha\');" />';
/*
*/
echo '</div>';
/* **** End CAPTCHA **** */
echo '</div>';
echo '<div class="clear_div"></div>';
echo '<input type="submit" name="submit" value="Submit" />';
echo '</form>';
echo '</div>';
if (!empty($js_string)) :
echo '<script>';
echo '$(document).ready(function() {';
echo $js_string;
echo '});';
echo '</script>';
endif;
endif;
//var_dump_pre($_POST);
$out = ob_get_clean();
return $out;
}
function lcs_pdb_parse_placeholders($text)
{
foreach($_POST as $key => $value) :
$text = str_ireplace('['.$key.']', $value, $text);
endforeach;
return $text;
}
function lcs_pdb_sys_encrypt($string, $key) {
return @openssl_encrypt($string, 'AES-128-CFB', $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING);
}
function lcs_pdb_sys_decrypt($string, $key) {
return @openssl_decrypt($string, 'AES-128-CFB', $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING);
}