1_contests = { 2 3 clickedAt: 0, 4 5 registration: async function () {//bisogna salvare il session_number (il numero di sessione in cui l'utente si registra a un promobox) 6 var email = $('#contest-email').val().trim().toLowerCase(); 7 var firstName = $('#contest-name').val().trim(); 8 var lastName = $('#contest-surname').val().trim(); 9 var tel = $('#contest-tel').val().trim().replaceAll(" ", "").replaceAll(".", "").replaceAll("/", ""); 10 var gender = ""; 11 if ($("input[class=gender]:checked").length > 0) 12 gender = $("input[class=gender]:checked")[0].name; 13 var postal_code = $('#contest-postal_code').val().trim(); 14 var appName = _config.app.radio.name //nome dell'app da cui è stata fatta la giocata 15 var appOrSite = "" //giocata fatta da app o sito 16 if(_system.isBrowser()) { 17 appOrSite = "browser" 18 } 19 else{ 20 appOrSite = "app" 21 } 22 23 var ip; //indirizzo ip del dispositivo da cui è stata fatta la giocata 24 await $.getJSON("https://api.ipify.org/?format=json", function(e) { 25 ip = e.ip; 26 }); 27 //var birthl = $('#contest-birthl').val().trim(); 28 var birthd = $('#contest-birthd').val(); //$('#contest-birthd').val(_profile._data.birthday.slice(0, 4) + "-" + _profile._data.birthday.slice(4, 6) + "-" + _profile._data.birthday.slice(6, 8)); 29 var terms = $('#contest-check').is(":checked"); 30 if (email == "" || firstName == "" || lastName == "" || tel == "" || /*birthl == "" ||*/ birthd == "" || gender == "" || postal_code == "") { 31 _toastmessage.show("501", "error"); 32 return; 33 } 34 if (_init._contest['configs']['flag']['adult'] == true) { 35 if (_system.dateDiff(birthd, _time.dateNow(), "years") < 18) { 36 _toastmessage.showMessage("Ci spiace! Il concorso è riservato ai maggiorenni.", "error"); 37 return; 38 } 39 } 40 41 if (terms !== true) { 42 _toastmessage.show("556", "error"); 43 return; 44 } 45 46 $('#button-contest').addClass("loader"); 47 48 var token = _app.contestId + "-" + _profile._data.id; 49 var data = { 50 email: email, 51 user_id: _profile._data.id, 52 firstname: firstName, 53 lastname: lastName, 54 birth_date: birthd.replaceAll("-", ""),//_system.dateToEpoch(birthd + " 12:00:00"), 55 //birth_location: birthl, 56 phone: tel, 57 gender: gender, 58 postal_code: postal_code, 59 check_privacy: _profile._data.check.privacy, 60 check_terms: terms, 61 check_marketing: _profile._data.check.marketing, 62 token: token, 63 contest_id: _app.contestId, 64 created_at: firebase.database.ServerValue.TIMESTAMP, 65 updated_at: firebase.database.ServerValue.TIMESTAMP, 66 clicked_at: _contests.clickedAt, //ora in cui è stata fatta la giocata 67 session_number: _init._contest.session_number, 68 appName: appName, 69 appOrSite: appOrSite, 70 url: window.location.href,//url da cui è stata fatta la giocata --> window location href 71 ip: ip, 72 }; 73 var _this = this; 74 var refContest = "groups/" + _config.app.radio.group + "/radios/" + _config.app.radio.id + "/logs/contests/"; 75 firebase.database().ref(refContest).orderByChild("token").equalTo(token).once("value") 76 .then(function (dataCheck) { 77 var userSubscriptions = dataCheck.val() 78 var check_session_number = true; 79 80 if (userSubscriptions !== null) { 81 if (Object.keys(userSubscriptions).length > 0) { 82 for (i = 0; i < Object.keys(userSubscriptions).length; i++) { 83 if (userSubscriptions[Object.keys(userSubscriptions)[0]].session_number === _init._contest.session_number) { 84 check_session_number = false; 85 } 86 } 87 } 88 } 89 90 if (check_session_number) { 91 firebase.database().ref(refContest + _system.key()).set(data) 92 .then(function () { 93 $('#contest-name').val("");
94 $('#contest-surname').val(""); 95 $('#contest-email').val(""); 96 //$('#contest-birthl').val(""); 97 $('#contest-birthd').val(""); 98 $('#contest-tel').val(""); 99 $('#button-contest').removeClass("loader"); 100 _toastmessage.show("205"); 101 _navigator.home.main(); 102 }) 103 } 104 else { 105 $('#button-contest').removeClass("loader"); 106 _toastmessage.show("520", "error"); 107 return; 108 } 109 }); 110 /*firebase.database().ref(refContest).orderByChild("token").equalTo(token).once("value") 111 .then(function (dataCheck) { 112 if (dataCheck.val() === null) { 113 firebase.database().ref(refContest).orderByChild("user_id").equalTo(_profile._data.id).once("value") 114 .then(function (dataCheck) { 115 var mySubscriptions = dataCheck.val(); 116 var found = false; 117 //for su mySubscriptions: cerco session_number. Se lo trovo, mi sono già registrato quindi non puoi registrarti di nuovo, altrimenti vai avanti 118 for (key in mySubscriptions) { 119 if (mySubscriptions[key]['contest_id'] == _app.contestId) found = true; 120 } 121 if (!found) { 122 firebase.database().ref(refContest).orderByChild("phone").equalTo(tel).once("value") 123 .then(function (dataCheck) { 124 var mySubscriptions = dataCheck.val(); 125 var found = false; 126 for (key in mySubscriptions) { 127 if (mySubscriptions[key]['contest_id'] == _app.contestId) found = true; 128 } 129 if (!found) { 130 firebase.database().ref(refContest + _system.key()).set(data) 131 .then(function () { 132 $('#contest-name').val(""); 133 $('#contest-surname').val(""); 134 $('#contest-email').val(""); 135 //$('#contest-birthl').val(""); 136 $('#contest-birthd').val(""); 137 $('#contest-tel').val(""); 138 $('#button-contest').removeClass("loader"); 139 _toastmessage.show("205"); 140 _navigator.home.main(); 141 }) 142 } else { 143 $('#button-contest').removeClass("loader"); 144 _toastmessage.show("520", "error"); 145 return; 146 } 147 }); 148 } else { 149 $('#button-contest').removeClass("loader"); 150 _toastmessage.show("520", "error"); 151 return; 152 } 153 }); 154 } else { 155 $('#button-contest').removeClass("loader"); 156 _toastmessage.show("520", "error"); 157 return; 158 } 159 }).catch(function () { 160 $('#button-contest').removeClass("loader"); 161 _toastmessage.show("520", "error"); 162 return; 163 });*/ 164 }, 165 166 open: function () { 167 var _this = this; 168 169 if (_profile.isLogged() && _init._contest !== null) { 170 171 // var nowFromMidnight = _time.now().hour * 60 * 60 * 1000 + _time.now().minute * 60 * 1000 172 // var todayMidnight = _time.now().ts - nowFromMidnight; 173 var now = new Date(); 174 var offsetMinutes = now.getTimezoneOffset(); 175 var offsetHours = offsetMinutes/60;
176 var nowFromMidnight = (now.getUTCHours() - offsetHours)* 60 * 60 * 1000 + now.getUTCMinutes() * 60 * 1000; 177 // var todayMidnight = Date.now() - nowFromMidnight -Date.now().getUTC; 178 var todayMidnight = new Date(); 179 todayMidnight.setUTCHours(0,0,0,0); 180 todayMidnight = todayMidnight.getTime(); 181 _init._contest.session_number = -1; 182 if (_init._contest["daa_schedulation"] !== undefined && _init._contest["daa_schedulation"].length > 0) { 183 for (var i = 0; i < _init._contest["daa_schedulation"].length; i++) { 184 //check the date & time_from and time_to are in milliseconds from midnight 185 if (todayMidnight >= _init._contest["daa_schedulation"][i]["date_from"] && 186 todayMidnight <= _init._contest["daa_schedulation"][i]["date_to"] && 187 nowFromMidnight >= _init._contest["daa_schedulation"][i]["time_from"] && 188 nowFromMidnight <= _init._contest["daa_schedulation"][i]["time_to"]) { 189 _init._contest['session_number'] = todayMidnight + _init._contest["daa_schedulation"][i]["time_from"]; 190 break; 191 } 192 } 193 } else { 194 if (_init._contest["schedulation"] !== undefined && _init._contest["schedulation"].length > 0) { 195 for (var i = 0; i < _init._contest["schedulation"].length; i++) { 196 //check the date & time_from and time_to are in milliseconds from midnight 197 if (_system.dateDiff(_init._contest["schedulation"][i]["date"], _time.now().ts, "days") == 0 && 198 nowFromMidnight >= _init._contest["schedulation"][i]["time_from"] && 199 nowFromMidnight <= _init._contest["schedulation"][i]["time_to"]) { 200 _init._contest['session_number'] = i; 201 } 202 } 203 } 204 } 205 206 if (_init._contest.session_number == -1) { 207 _toastmessage.show("519", "error"); 208 return; 209 } 210 211 _this.clickedAt = _time.now().ts; 212 213 var contest = _init._contest; 214 foundContest = true; 215 _app.contestId = contest['_id']; 216 var title = contest['title']; 217 var image = contest['image']; 218 var description = contest['abstract']; 219 $('.contest-title').html(title); 220 $('.contest-description').html(description); 221 if (image !== "") { 222 $('.contest-image').show(); 223 $('.contest-image img').attr("src", image); 224 } else { 225 $('.contest-image').hide(); 226 } 227 if (contest['configs']['url']['terms'] !== "") $('.contest-terms').attr("href", contest['configs']['url']['terms']); 228 if (contest['configs']['url']['privacy'] !== "") $('.contest-privacy').attr("href", contest['configs']['url']['privacy']); 229 if (contest['configs']['label_submit'] !== "") $('#button-contest').text(contest['configs']['label_submit']); 230 if (contest['configs']['flag']['adv'] === true) { 231 $('#contest-check-marketing-container').show(); 232 if (contest['configs']['flag_content_adv'] !== undefined && contest['configs']['flag_content_adv'] !== "") { 233 if (contest['configs']['url']['adv'] !== undefined && contest['configs']['url']['adv'] !== "") { 234 $('#contest-check-marketing-label').html("<a href='" + contest['configs']['url']['adv'] + "' target='_blank'>" + contest['configs']['flag_content_adv'] + "</a>"); 235 } else { 236 $('#contest-check-marketing-label').html(contest['configs']['flag_content_adv']); 237 } 238 } else { 239 var labelMarketing = "Acconsento all'utilizzo dei miei dati per fini di marketing"; 240 if (contest['configs']['url']['adv'] !== undefined && contest['configs']['url']['adv'] !== "") { 241 $('#contest-check-marketing-label').html("<a href='" + contest['configs']['url']['adv'] + "' target='_blank'>" + labelMarketing + "</a>"); 242 } else { 243 $('#contest-check-marketing-label').text(labelMarketing); 244 } 245 } 246 } else { 247 $('#contest-check-marketing-container').hide(); 248 } 249 var token = _app.contestId + "-" + _profile._data.id; 250 firebase.database().ref("groups/" + _config.app.radio.group + "/radios/" + _config.app.radio.id + "/logs/contests").orderByChild("token").equalTo(token).once("value") 251 .then(function (data) { 252 var userSubscriptions = data.val() 253 var check_session_number = true; 254 255 if (userSubscriptions !== null) { 256 if (Object.keys(userSubscriptions).length > 0) { 257 for (i = 0; i < Object.keys(userSubscriptions).length; i++) { 258 if (userSubscriptions[Object.keys(userSubscriptions)[0]].session_number === _init._contest.session_number) { 259 check_session_number = false;
260 } 261 } 262 } 263 } 264 265 if (check_session_number) { 266 if (_profile._data.firstname !== undefined) { 267 $('#contest-name').val(_profile._data.firstname); 268 } 269 if (_profile._data.lastname !== undefined) { 270 $('#contest-surname').val(_profile._data.lastname); 271 } 272 if (_profile._data.email !== undefined) { 273 $('#contest-email').val(_profile._data.email); 274 } 275 if (_profile._data.phone !== undefined) { 276 $('#contest-tel').val(_profile._data.phone); 277 } 278 if (_profile._data.birthday !== undefined && _profile._data.birthday != 0) { 279 $('#contest-birthd').val(_profile._data.birthday.slice(0, 4) + "-" + _profile._data.birthday.slice(4, 6) + "-" + _profile._data.birthday.slice(6, 8)); 280 } 281 if (_profile._data.postal_code !== undefined) { 282 $('#contest-postal_code').val(_profile._data.postal_code); 283 } 284 if (_profile._data.gender !== undefined) { 285 $("#contest-gender-" + _profile._data.gender).prop("checked", true) 286 } 287 _navigator.contest.main(); 288 } else { 289 _navigator.contest.blocked(); 290 } 291 }); 292 293 } else { 294 if (_profile.isLogged() === false) { 295 _toastmessage.show(518, "error"); 296 } else { 297 _toastmessage.show(519, "warning"); 298 } 299 } 300 }, 301 302 checkGender: function (genderFirst, genderSecond, genderThird) { 303 if ($("#contest-gender-" + genderFirst).is(":checked")) { 304 $("#contest-gender-" + genderSecond).prop("checked", false); 305 $("#contest-gender-" + genderThird).prop("checked", false); 306 } 307 }, 308}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.