// to get the correct TI IIRS_0_debug_print("updating TI details..."); $values = array('name' => $initiative_name, 'summary' => $summary, 'domain' => $domain, 'town_name' => $town_name, 'location_latitude' => $location_latitude, 'location_longitude' => $location_longitude, 'location_description' => $location_description, 'location_country' => $location_country, 'location_full_address' => $location_full_address, 'location_granuality' => $location_granuality, 'location_bounds' => $location_bounds); $ret = IIRS_0_TI_update_TI($values); if (IIRS_is_error($ret)) { $IIRS_error = $ret; } } // ------------------------------------------------------------- load current values // this page only works with a single user that has only 1 registered TI // it does not handle users who have registered multiple TIs $is_user_with_one_TI = false; $location_uniques = array(); if (IIRS_0_logged_in()) { IIRS_0_debug_print("loading user details..."); if ($user = IIRS_0_details_user()) { $name = $user['name']; $email = $user['email']; $phone = isset($user['phone']) ? $user['phone'] : null; IIRS_0_debug_print("loading TI [" . IIRS_0_CONTENT_TYPE . "] details..."); $TI = IIRS_0_details_TI_user(); if (is_array($TI)) { $is_user_with_one_TI = true; $initiative_name = $TI['name']; $summary = $TI['summary']; $domain = $TI['domain']; // values fo the desciption LI $location_array['description'] = $TI['location_description']; $location_array['latitude'] = $TI['location_latitude']; $location_array['longitude'] = $TI['location_longitude']; $location_array['country'] = $TI['location_country'];
function IIRS_0_TI_verify_add_TI($user_ID, $IIRS_host_domain, $initiative_name, $town_name, $location_latitude, $location_longitude, $location_description, $location_country, $location_full_address, $location_granuality, $location_bounds, $domain) { // on success returns the native TI ID // on failure returns NULL $ret = null; // --------------------------------------- 1) check data input validity // the user is already registered, so we can use IIRS_0_details_user() // TODO: concurrency issues with registration if (!is_numeric($location_latitude) || !is_numeric($location_longitude)) { $ret = new IIRS_Error(IIRS_INVALID_TI_INPUTS, 'We think you are a SPAM robot. please email us to resolve this issue.', 'location data is not numeric', IIRS_MESSAGE_USER_ERROR, IIRS_MESSAGE_NO_USER_ACTION, array('$location_latitude' => $location_latitude, '$location_longitude' => $location_longitude)); } // --------------------------------------- 2) check user 1-1 TI relation if (!$ret) { $TI = IIRS_0_details_TI_user(); // returns NULL if no TI associated if (is_array($TI)) { $ret = new IIRS_Error(IIRS_USER_ALREADY_HAS_TI, 'You have already registered a Transition Initiative under this username. Please logout and re-register', "User already associated with TI [{$TI['name']}]", IIRS_MESSAGE_USER_ERROR, IIRS_MESSAGE_NO_USER_ACTION, $TI); } elseif (IIRS_is_error($TI)) { $ret = $TI; } } // --------------------------------------- 3) check duplicate registration by vicinity // currently disabled. will always return ok if (!$ret) { $vicinity_match = IIRS_0_TI_vicinity_match($location_latitude, $location_longitude, $location_description); if ($vicinity_match === TRUE || IIRS_is_error($vicinity_match)) { $ret = $vicinity_match; } } // --------------------------------------- 4) check duplicate TI name if (!$ret) { $TI_same_name = IIRS_0_TI_same_name($initiative_name); // returns a TI or FALSE or [system] IIRS_Error if (is_array($TI_same_name)) { // ok, so we have a registration with an identical name // same name entries are not necessarily close by. America and UK will have many name conflicts // reject this currently. ask for an alternative name // this might cause the user to experience surprise, anger, competition. // needs to be handled with emotional intelligence, i.e.: // hey! we've found someone you can chat and work with in your space! // OR // someone OWNS this name and you are not permitted to create an Initiative here. IIRS_0_debug_var_dump($TI_same_name); $ret = new IIRS_Error(IIRS_TI_EXISTS_SAME_NAME, 'A Transition Initiative already exists with this name. Please add something to the name or change it and try again', 'TI Name matched exactly in data verification stage', IIRS_MESSAGE_USER_WARNING, IIRS_MESSAGE_NO_USER_ACTION, array('$TI_same_name' => $TI_same_name)); } elseif (IIRS_is_error($TI_same_name)) { $ret = $TI_same_name; } } // --------------------------------------- 5) check for SPAM using AKISMET // IIRS_0_akismet_check_ti_registration_name() returns true for is SPAM if (!$ret) { $is_SPAM = IIRS_0_akismet_check_ti_registration_name(IIRS_0_details_user(), $initiative_name); if ($is_SPAM === TRUE) { $ret = new IIRS_Error(IIRS_AKISMET_SAYS_SPAM, 'Akismet thinks that your entry is SPAM. So we cannot accept it. Sorry.', 'Akismet returned true for SPAM detection', IIRS_MESSAGE_USER_ERROR, IIRS_MESSAGE_NO_USER_ACTION, array('$initiative_name' => $initiative_name)); } elseif (IIRS_is_error($is_SPAM)) { $ret = $is_SPAM; } } // --------------------------------------- F) FINAL: if no vertification issues registrered then everything ok if (!$ret) { // ask host framework to add the TI $ret = IIRS_0_TI_add_TI($user_ID, $IIRS_host_domain, $initiative_name, $town_name, $location_latitude, $location_longitude, $location_description, $location_country, $location_full_address, $location_granuality, $location_bounds, $domain); } return $ret; }