| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | if ( elgg_is_active_plugin('web_services') && elgg_is_active_plugin('gcRegistration_invitation') && elgg_get_config('allow_registration') ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | 	elgg_ws_expose_function( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | 		"gc.invite", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | 		"talent_cloud_invite", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | 		array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | 			"email" => array('type' => 'string', 'required' => true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | 		), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | 		'Invites Talent Cloud user to register for GCcollab Account', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | 		'POST', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 		true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 		false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 	); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 	function talent_cloud_invite($email) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 		// validation on email address | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 		if(!is_email_address($email)){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 			return json_encode(array('success'=>false,'error'=>'The email submitted is not a valid email')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 		}; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 		$email = trim($email); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	    // Create TalentCloud user if they don't exist | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 		$api_user = get_user_by_username('TalentCloud'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 		if (!$api_user){; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 			$api_user = register_user('TalentCloud',substr(str_shuffle(md5(time())),0,10), 'TalentCloud', '[email protected]', false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 		}; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 		// Check to see if invitaiton exists, if yes then we only need to send email and not register address again | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 37 |  | View Code Duplication | 		if (!invitationExists($email)){			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 			$data = array('inviter' => $api_user->guid, 'emails' => [$email]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 			elgg_trigger_plugin_hook('gcRegistration_email_invitation', 'all', $data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 		}; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 		// Get site variables to construct email message | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 		$site = elgg_get_site_entity(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 		// Set custom personalized message | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 		$emailmessage_en = 'Personalized message from GC Talent Cloud'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 		$emailmessage_fr = 'Message personalisé de Nuage de talents du GC'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 		$link_en = "<a href='https://account.gccollab.ca/register/'>GCcollab Account Registration</a>"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 		$link_fr = "<a href='https://account.gccollab.ca/register/'>Compte GCcollab pour créer un compte</a>"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 		$subject = elgg_echo('cp_notify:subject:invite_new_user',array(),'en') . ' | ' . elgg_echo('cp_notify:subject:invite_new_user',array(),'fr'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 		$cp_notify_msg_title_en = elgg_echo('cp_notify:body_invite_new_user:title', array('GC Talent Cloud'),'en'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 		$cp_notify_msg_title_fr = elgg_echo('cp_notify:body_invite_new_user:title', array('Nuage de talents du GC'),'fr'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 		$cp_notify_msg_description_en = elgg_echo('cp_notify:body_invite_new_user:description',array('GC Talent Cloud', $emailmessage_en, $link_en),'en'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 		$cp_notify_msg_description_fr = elgg_echo('cp_notify:body_invite_new_user:description',array('Nuage de talents du GC', $emailmessage_fr, $link_fr),'fr'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 		$email_notification_header = elgg_echo('cp_notification:email_header',array(),'en') . ' | ' . elgg_echo('cp_notification:email_header',array(),'fr'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		$french_follows = elgg_echo('cp_notify:french_follows',array()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 		$current_year = date('Y'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		$current_site = elgg_get_site_entity()->name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 		$template = elgg_echo(" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 			<html> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 			<body> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 				<!-- beginning of email template --> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 				<div width='100%' bgcolor='#fcfcfc'> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 					<div> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 						<div> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 							<div align='center' width='100%' style='background-color:#f5f5f5; padding:20px 30px 15px 30px; font-family: sans-serif; font-size: 12px; color: #79579D'> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 								{$email_notification_header} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 							</div> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 							<div width='100%' style='padding: 0 0 0 10px; color:#ffffff; font-family: sans-serif; font-size: 35px; line-height:38px; font-weight: bold; background-color:#46246A;'> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 								<span style='padding: 0 0 0 3px; font-size: 20px; color: #ffffff; font-family: sans-serif;'>GCcollab</span> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 							</div> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 							<div style='height:1px; background:#bdbdbd; border-bottom:1px solid #ffffff'></div> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 							<div width='100%' style='padding:30px 30px 10px 30px; font-size:12px; line-height:22px; font-family:sans-serif;'> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 								<span style='font-size:12px; font-weight: normal;'>{$french_follows}</span><br/> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 							</div> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 							<div width='100%' style='padding:30px 30px 30px 30px; color:#153643; font-family:sans-serif; font-size:16px; line-height:22px; '> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 								<h4 style='padding: 0px 0px 5px 0px; font-family:sans-serif';> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 									<strong> {$cp_notify_msg_title_en} </strong> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 								</h4> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 								{$cp_notify_msg_description_en} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 							</div> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 							<div style='margin-top:15px; padding: 5px; color: #6d6d6d; border-bottom: 1px solid #ddd;'> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 							</div> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 							<div width='100%' style='padding:30px 30px 30px 30px; color:#153643; font-family:sans-serif; font-size:16px; line-height:22px;'> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 								<h4 style='padding: 0px 0px 5px 0px; font-family:sans-serif;'> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 									<strong> {$cp_notify_msg_title_fr} </strong> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 								</h4> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 								{$cp_notify_msg_description_fr} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 							</div> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 								<div style='margin-top:15px; padding: 5px; color: #6d6d6d;'> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 							</div> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 							<div style='height:1px; background:#bdbdbd; border-bottom:1px solid #ffffff'></div> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 							<div align='center' width='100%' style='background-color:#f5f5f5; padding:20px 30px 15px 30px; font-family: sans-serif; font-size: 16px; color: #79579D'> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 								{$current_site} © {$current_year} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 							</div> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 						</div> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 					</div> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 				</div> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 			</body> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 			</html>"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 		$result = phpmailer_send($email, $email, $subject, $template, NULL, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 		if ($result){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 			return json_encode(array('success'=>'true')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 			return json_encode(array('success'=>'false', 'error'=>'Error trying to send email')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 	}; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 140 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  | 	function invitationExists($emailaddress){ | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  | 		$query = "SELECT * FROM email_invitations WHERE `email` = '" . $emailaddress . "'"; | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  | 		$result = get_data($query); | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  | 		if (count($result) > 0){ | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  | 			return true; | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  | 		} else{ | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  | 			return false; | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  | 		}; | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  | 	}; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | }; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | 	 | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 155 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 156 |  |  |  |