public function merge_to_ocean()
 {
     $result = array("status" => false, "message" => "");
     if (is_logged_in()) {
         $mr_id = $this->input->post('m_strm', true);
         $or_id = $this->input->post('o_strm', true);
         $logged_id = $this->get_logged_uid();
         $mr_data = $this->get_single_river($mr_id);
         $or_data = $this->get_single_river($or_id);
         if ($mr_data['status'] == true) {
             $mr = $mr_data['data'];
             #$ms_sys_id = $ms['eco_sys_id'];
             if ($or_data['status'] == true) {
                 $or = $or_data['data'];
                 #$os_sys_id = $os['eco_sys_id'];
                 if (!$this->is_already_merged($mr['id'])) {
                     if (!$this->is_already_merged($or['id'])) {
                         if (!$this->is_already_requested($logged_id, $mr['id'], $or['id'])) {
                             if (!$this->is_ready_for_ocean($logged_id, $mr['id'], $or['id'])) {
                                 $merge_request = $this->add_request_to_merge($logged_id, $mr['id'], $or['id']);
                                 if ($merge_request['status'] == true) {
                                     $config = c_get_config();
                                     $user = $this->is_valid_user($this->get_logged_uid());
                                     $other_user = $this->Mod_User->get_user($or['moderator_id']);
                                     $mr_link = "<a href='" . base_url() . $config['single_river_url'] . "/{$mr[id]}'>{$mr[question_text]}</a>";
                                     $or_link = "<a href='" . base_url() . $config['single_river_url'] . "/{$or[id]}'>{$or[question_text]}</a>";
                                     $notif_details = "{$user[name]}<br />\n                                                          Invite Request for Creating Ocean<br />\n                                                          Hi {$other_user[name]}, I would like to merge my river \n                                                          {$mr_link} with your river {$or_link} \n                                                          due to our cause and awareness message and I would like to<br /> \n                                                          <br />\n                                                          promote it mutually.<br />\n                                                          Approval required, thanks.<br />";
                                     $notif_data = array('template_id' => "6", 'user_id' => "{$or['moderator_id']}", 'from_user_id' => "{$logged_id}", 'objects' => "River:River", 'object_id' => "{$merge_request[data][id]}", 'object_location' => 'eco_merge_requests', 'visit_url' => "ecosystem/invitation", 'notif_details' => $notif_details);
                                     generate_notification($notif_data, true);
                                     $result['status'] = true;
                                     $result['message'] = "Request sent.";
                                 } else {
                                     $result['message'] = $merge_request['message'];
                                 }
                             } else {
                                 $result['message'] = "River already ready for creating ocean.";
                             }
                         } else {
                             $result['message'] = "Request already sent.";
                         }
                     } else {
                         $result['message'] = "River already merged.";
                     }
                 } else {
                     $result['message'] = "River already merged.";
                 }
             } else {
                 $result['message'] = "Invalid river.";
             }
         } else {
             $result['message'] = "Invalid your river.";
         }
     } else {
         $result['message'] = "Login first.";
     }
     return $result;
 }
function generate_ppoints($user_id, $action_keys, $action_amount = 0)
{
    if ($user_id <= 0 || empty($action_keys)) {
        return false;
    }
    #/ get PP-Config data
    $sql_1 = "SELECT * FROM patronage_points_config";
    if (is_int($action_keys)) {
        $sql_1 .= " WHERE id='{$action_keys}' AND is_active='1'";
    } else {
        $sql_1 .= " WHERE action_key='{$action_keys}' AND is_active='1'";
    }
    $ppc_info = format_str(@mysql_exec($sql_1, 'single'));
    if (!is_array($ppc_info) || !array_key_exists('points', $ppc_info)) {
        return false;
    }
    #/ Get User and their PP Info (within last 24 hours only), against the given Key
    $sql_2 = "SELECT u.id AS u_id, upp.*, (NOW() - INTERVAL 1 DAY) intvervl\n    FROM users u\n    LEFT JOIN user_petronage_points upp ON (upp.user_id=u.id) AND (pp_config_id='{$ppc_info['id']}') AND (received_on > (NOW() - INTERVAL 1 DAY))\n    WHERE u.id='{$user_id}'";
    $upp_info = format_str(@mysql_exec($sql_2));
    if (!is_array($upp_info) || count($upp_info) <= 0) {
        return false;
    }
    #/ Check Limits
    $limits_per_day = (int) @$ppc_info['limits_per_day'];
    $total_given_today = 0;
    foreach ($upp_info as $uiv) {
        if (isset($uiv['points_received']) && !empty($uiv['points_received'])) {
            $total_given_today++;
        }
    }
    //var_dump("<pre>", $limits_per_day, $total_given_today, $ppc_info['id'], $user_id); die();
    if ($limits_per_day > 0 && $total_given_today >= $limits_per_day) {
        return false;
    }
    #/ Calculate Points to be given
    $points = (int) $ppc_info['points'];
    $ppc_info['percentage_points'] = (int) $ppc_info['percentage_points'];
    if ($ppc_info['points'] == '0' && $ppc_info['percentage_points'] > 0 && $action_amount > 0) {
        $points = round($action_amount * ($ppc_info['percentage_points'] / 100));
    }
    #/ Allocate Points when all is checked above
    $sql_3 = "INSERT INTO user_petronage_points\n\t(user_id, pp_config_id, points_received, received_on)\n    VALUES('{$user_id}', '{$ppc_info['id']}', '{$points}', NOW())";
    @mysql_exec($sql_3, 'save');
    $upp_id = @mysql_insert_id();
    if ($points > 0) {
        $sql_4 = "UPDATE user_info SET total_patronage_points = (total_patronage_points+'{$points}')\n    WHERE user_id='{$user_id}'";
        @mysql_exec($sql_4, 'save');
    }
    #/ Generate PP Notification
    if (function_exists('generate_notification') != true) {
        include_once '../includes/notif_func.php';
    }
    $notif_data = array('template_id' => "10", 'user_id' => "{$user_id}", 'from_user_id' => "0", 'objects' => "{$points}:{$ppc_info['category']}", 'object_id' => "{$upp_id}", 'object_location' => 'user_petronage_points', 'visit_url' => '');
    generate_notification($notif_data);
    return $points;
}
Esempio n. 3
0
 public function update_by($key, $key_value, $data, $message = '', $delete_cache = 'y')
 {
     $this->db->where($key, $key_value);
     $this->db->update($this->_tablename, $data);
     //echo $this->db->last_query();
     //generate message
     if ($message) {
         //generate notification
         generate_notification($message, 'alert alert-info');
     }
     if ($delete_cache == 'y') {
         //clear cache
         $this->db->cache_delete_all();
         emptyDirectory($this->_cache_path);
     }
     return $this->db->affected_rows();
 }
 public function reject_ocean_invite()
 {
     $result = array("status" => false, "message" => "");
     if (is_logged_in()) {
         $caller_sys_id = $this->input->post('csid', true);
         $receiver_sys_id = $this->input->post('rsid', true);
         $merged_request = $this->get_merged_request_by_cr($caller_sys_id, $receiver_sys_id);
         if ($merged_request) {
             if ($merged_request['verification_str'] == '') {
                 $caller_eco_system = $this->get_eco_system_by_user($caller_sys_id, $merged_request['requested_by']);
                 if ($caller_eco_system) {
                     $receiver_eco_system = $this->get_eco_system_by_user($receiver_sys_id, $this->get_logged_uid());
                     if ($receiver_eco_system) {
                         $notif_details = "Your request to create a Ocean is rejected unfortunately by the moderator of \"River\".";
                         $notif_data = array('template_id' => "11", 'user_id' => "{$caller_eco_system[moderator_id]}", 'from_user_id' => "{$receiver_eco_system[moderator_id]}", 'objects' => "River:River", 'object_id' => "{$merged_request[id]}", 'object_location' => 'eco_merge_requests', 'visit_url' => "ecosystem/notification", 'notif_details' => $notif_details);
                         generate_notification($notif_data, true);
                         // delete other request to merge request table
                         $this->db->where("(caller_eco_sys_id='{$caller_sys_id}' AND receiver_eco_sys_id='{$receiver_sys_id}')");
                         $this->db->delete('eco_merge_requests');
                         $sql = "SELECT * FROM user_notifications WHERE object_id=? ORDER BY id ASC LIMIT 1";
                         $rsl = $this->db->query($sql, array($merged_request['id']));
                         if ($rsl->num_rows() > 0) {
                             $row = $rsl->row_array();
                             // delete notification
                             $this->db->where('id', $row['id']);
                             $this->db->delete('user_notifications');
                         }
                         $result['status'] = true;
                         $result['message'] = "Request rejected successfully.";
                     } else {
                         $result['message'] = 'Receiver invalid.';
                     }
                 } else {
                     $result['message'] = 'Caller invalid.';
                 }
             } else {
                 $result['message'] = "Request already accepted.";
             }
         } else {
             $result['message'] = "Invalid caller and receiver.";
         }
     } else {
         $result['message'] = "Login first.";
     }
     return $result;
 }
{OBJECT}

{OBJECT2}
{USER2} //receiver
*/
#/ example = Welcome
$notif_data = array('template_id' => "5", 'user_id' => "23", 'from_user_id' => "0", 'objects' => '', 'object_id' => '0', 'object_location' => '', 'visit_url' => '');
//generate_notification($notif_data, true); die();
//-------------
#/ example = Payment Success
$notif_data = array('template_id' => "7", 'user_id' => "{$user_id}", 'from_user_id' => "0", 'objects' => "CUSA-654643643", 'object_id' => '0', 'object_location' => '', 'visit_url' => '');
//generate_notification($notif_data, true); die();
//-------------
#/ example = FB Share
$notif_data = array('template_id' => "4", 'user_id' => "{$user_id}", 'from_user_id' => "23", 'objects' => "Voice", 'object_id' => '11', 'object_location' => 'user_voices', 'visit_url' => 'ecosystem/11');
generate_notification($notif_data, true);
die;
//-------------
#/ example = Reply to Discussion
$notif_details = "<span style=\"color:#2CA1F4;\">Lorem ipsum dolor sit amet, consectetuer adipiscing elit</span><br />\n<div>JoanJGarcia: \"Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat\"</div>";
$notif_data = array('template_id' => "1", 'user_id' => "{$user_id}", 'from_user_id' => "3", 'objects' => "Stream", 'object_id' => '1', 'object_location' => 'eco_discussion_comments', 'visit_url' => 'ecosystem/stream/1', 'notif_details' => $notif_details);
//generate_notification($notif_data, true); die();
//-------------
#/ example = merger invitation
$notif_details = "<span style='color:#464646;'>Your Stream: <a href=\"my_stream_url\" style=\"color:#2CA1F4; text-decoration:none;\">Lorem ipsum dolor sit amet, consectetuer adipiscing elit</a> (Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat).</span><br /><br />\n<span style='color:#464646;'>Their Stream: <a href=\"user_stream_url\" style=\"color:#2CA1F4; text-decoration:none;\">Lorem ipsum dolor sit amet, consectetuer adipiscing elit</a> (Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat).</span><br />";
$notif_data = array('template_id' => "6", 'user_id' => "{$user_id}", 'from_user_id' => "3", 'objects' => "Stream:Stream", 'object_id' => '1', 'object_location' => 'eco_merge_requests', 'visit_url' => 'ecosystem/invitations', 'notif_details' => $notif_details);
//generate_notification($notif_data, true); die();
//-------------
#/ example = merger accepted
$notif_details = "<span style='color:#464646;'>Your Stream: <a href=\"my_stream_url\" style=\"color:#2CA1F4; text-decoration:none;\">Lorem ipsum dolor sit amet, consectetuer adipiscing elit</a> (Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat).</span><br /><br />\n<span style='color:#464646;'>Their Stream: <a href=\"user_stream_url\" style=\"color:#2CA1F4; text-decoration:none;\">Lorem ipsum dolor sit amet, consectetuer adipiscing elit</a> (Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat).</span><br />";
$notif_data = array('template_id' => "8", 'user_id' => "{$user_id}", 'from_user_id' => "3", 'objects' => "Stream:Stream", 'object_id' => '1', 'object_location' => 'eco_merge_requests', 'visit_url' => 'ecosystem/invitations', 'notif_details' => $notif_details);
function save_user_payment($user_id, $user_POST, $save_arr, $attempted_on)
{
    global $seo_tag, $consts;
    #/ Save user_payments
    $sql_1 = "INSERT INTO user_payments (user_id, invoice, amount, transaction_id, gateway_name, gateway_payer_id, gateway_msg, payment_status, paid_on)\n    values ('{$user_id}', '', '{$save_arr['amount']}', '{$save_arr['transaction_id']}', '{$save_arr['gateway_name']}', '{$save_arr['gateway_payer_id']}', '{$save_arr['gateway_msg']}', '{$save_arr['payment_status']}', '{$attempted_on}')";
    @mysql_exec($sql_1, 'save');
    $user_payment_id = (int) @mysql_insert_id();
    if ($user_payment_id > 0) {
        #/ Setup & Save Invoice ID
        $invoice_str = str_pad($user_payment_id, 4, "0", STR_PAD_LEFT);
        $user_id_str = str_pad($user_id, 3, "0", STR_PAD_LEFT);
        $invoice_id = 'CUSA-' . $user_id_str . '-' . $invoice_str;
        $sql_3 = "UPDATE user_payments SET invoice='{$invoice_id}' WHERE id='{$user_payment_id}'";
        @mysql_exec($sql_3, 'save');
        #/ Send Payment Email to User
        $subject = "[{$invoice_id}] Payment Receipt from collaborateUSA.com";
        $heading = "Payment Receipt & Invoice from collaborateUSA.com";
        $body_in = payment_receipt($invoice_id, $save_arr, $user_POST);
        send_mail($user_POST['email_add'], $subject, $heading, $body_in, 'collaborateUSA.com', $consts['mem_support_em']);
        #/ Send Payment Email to Admin
        $subject = "[{$invoice_id}] Payment Received at collaborateUSA.com";
        $heading = "Payment Invoice from collaborateUSA.com";
        $body_in = payment_invoice($invoice_id, $save_arr, $user_POST);
        send_mail($consts['mem_support_em'], $subject, $heading, $body_in);
        #/ Generate ThankYou Notification
        include_once '../includes/notif_func.php';
        $notif_data = array('template_id' => "7", 'user_id' => "{$user_id}", 'from_user_id' => "0", 'objects' => "{$invoice_id}", 'object_id' => '0', 'object_location' => '');
        @generate_notification($notif_data);
        #/ Allocate & Assign Patronage Points
        include_once '../includes/patronage_points_func.php';
        @generate_ppoints($user_id, 'join_share');
        #/ Clear Sessions
        unset($_SESSION['pay_chk']);
        unset($_SESSION['reshash']);
        unset($_SESSION['signup_cart']);
        unset($_SESSION['payer_id']);
        unset($_SESSION['Payment_Amount']);
        #/ Lock & Redirect
        $_SESSION['signup_success'] = '1';
        $_SESSION['signup_stage'] = 'signup-details';
        reset_attempt_counts();
        //redirect_me('signup-details'); //ajax based not possible to redirect
        return true;
    }
}